forked from Gigantua/Chess_Movegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
1436 lines (1230 loc) · 53.4 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <stdint.h>
#include <random>
#include <cmath>
#include <functional>
#include <cstdint>
#include <random>
#include <chrono>
#include <iomanip>
#include <string_view>
#include <type_traits>
#include <thread>
#include <vector>
#include <algorithm>
#include <numeric>
#include <tuple>
#ifdef _WIN32
#include <limits.h>
#include <intrin.h>
#else
#pragma clang diagnostic ignored "-Wignored-attributes"
#endif
class CPUID {
uint32_t regs[4];
public:
explicit CPUID(unsigned i) {
#ifdef _WIN32
__cpuid((int*)regs, (int)i);
#elif defined(__x86_64__) || defined(__i386__)
asm volatile
("cpuid" : "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
: "a" (i), "c" (0));
// ECX is set to zero for CPUID function 4
#else
char* vals = (char*)regs;
*vals++ = 'C'; *vals++ = 'P'; *vals++ = 'U'; *vals++ = ':'; *vals++ = ' ';
*vals++ = 'U'; *vals++ = 'n'; *vals++ = 'k'; *vals++ = 'o'; *vals++ = 'w'; *vals++ = 'n'; *vals++ = ' ';
*vals++ = 'A'; *vals++ = 'R'; *vals++ = 'M'; //Just unknown really
*vals++ = '\0';
#endif
}
const uint32_t& EAX() const { return regs[0]; }
const uint32_t& EBX() const { return regs[1]; }
const uint32_t& ECX() const { return regs[2]; }
const uint32_t& EDX() const { return regs[3]; }
};
static void PrintBrand() {
#if defined(__linux__) && (!defined(__x86_64__) && !defined(__i386__))
//Non x86/x64 Linux system
system("cat /proc/cpuinfo | grep model | grep name");
#else
uint32_t brand[12]{};
for (int i = 0; i < 3; i++)
{
CPUID d(0x80000002 + i);
brand[4*i + 0] = d.EAX();
brand[4*i + 1] = d.EBX();
brand[4*i + 2] = d.ECX();
brand[4*i + 3] = d.EDX();
}
printf("%s\n", (char*)brand);
#endif
}
#define Kogge_ (1)
#define Bob_ (1)
#define BobAdvanced_ (1)
#define Plain_ (1)
#define Fancy_ (1)
#define Pext_ (1)
#define SplitPext_ (1)
#define Kindergarten_ (1)
#define PextEmu_ (1)
#define Hyper_ (1)
#define Explode_ (1)
#define HypQsc_ (1)
#define HypQscNT_ (1)
#define Rotate_ (1)
#define Arithm_ (1)
#define Obstrd_ (1)
#define ObstrdNT_ (1)
#define QBB_ (1)
#define GeneticQBB_ (1)
#define HVar_ (1)
#define CMagic_ (1)
#define SMagic_ (1)
#define SMagic2_ (1)
#define Sissy_ (1)
#define KGSSB_ (1)
#define Dumb7_ (1)
#define AVXShift_ (1)
#define Leorik_ (1)
#define LeorikNT_ (1)
#define SBAMG_ (1)
#define SBAMGNT_ (1)
#define BinaryNetwork_ (1)
#define RotateBits_ (1)
#define Genetic8Ray_ (1)
#define GeneticObstruction_ (1)
#define GeneticObstructionV2_ (1)
#define FoldingHash_ (1)
#define GaloisField_ (1)
#define Gigantua_ (0)
#define MaskOf(X) _blsi_u64(X)
#define SquareOf(X) _tzcnt_u64(X)
#define Bitloop(X) for(;X; X = _blsr_u64(X))
#define Dummy(X) struct X {static inline constexpr std::string_view name = "dummy"; static void Prepare(uint64_t occ) {}static uint64_t Queen(int sq, uint64_t occ) { return 0; }};
static uint32_t rx = 123456789, ry = 362436069, rz = 521288629;
uint32_t rand32(void) { //2^96-1
uint32_t t;
rx ^= rx << 16; rx ^= rx >> 5; rx ^= rx << 1;
t = rx; rx = ry; ry = rz; rz = t ^ rx ^ ry;
return rz;
}
uint32_t rand32_state(uint32_t& x, uint32_t& y, uint32_t& z) { //2^96-1
uint32_t t;
x^= x<< 16; x^= x>> 5; x^= x<< 1;
t = x; x= y; y = z; z = t ^ x^ y;
return z;
}
uint64_t rand64() {
return ((uint64_t)rand32() << 32ull) | rand32();
}
uint64_t rand64_state(uint32_t& x, uint32_t& y, uint32_t& z) {
return (static_cast<uint64_t>(rand32_state(x,y,z)) << 32ull) | static_cast<uint64_t>(rand32_state(x,y,z));
}
#define Loop64(x, y) { \
{constexpr int x = 0; {y;} } \
{constexpr int x = 1; {y;} } \
{constexpr int x = 2; {y;} } \
{constexpr int x = 3; {y;} } \
{constexpr int x = 4; {y;} } \
{constexpr int x = 5; {y;} } \
{constexpr int x = 6; {y;} } \
{constexpr int x = 7; {y;} } \
{constexpr int x = 8; {y;} } \
{constexpr int x = 9; {y;} } \
{constexpr int x = 10; {y;} } \
{constexpr int x = 11; {y;} } \
{constexpr int x = 12; {y;} } \
{constexpr int x = 13; {y;} } \
{constexpr int x = 14; {y;} } \
{constexpr int x = 15; {y;} } \
{constexpr int x = 16; {y;} } \
{constexpr int x = 17; {y;} } \
{constexpr int x = 18; {y;} } \
{constexpr int x = 19; {y;} } \
{constexpr int x = 20; {y;} } \
{constexpr int x = 21; {y;} } \
{constexpr int x = 22; {y;} } \
{constexpr int x = 23; {y;} } \
{constexpr int x = 24; {y;} } \
{constexpr int x = 25; {y;} } \
{constexpr int x = 26; {y;} } \
{constexpr int x = 27; {y;} } \
{constexpr int x = 28; {y;} } \
{constexpr int x = 29; {y;} } \
{constexpr int x = 30; {y;} } \
{constexpr int x = 31; {y;} } \
{constexpr int x = 32; {y;} } \
{constexpr int x = 33; {y;} } \
{constexpr int x = 34; {y;} } \
{constexpr int x = 35; {y;} } \
{constexpr int x = 36; {y;} } \
{constexpr int x = 37; {y;} } \
{constexpr int x = 38; {y;} } \
{constexpr int x = 39; {y;} } \
{constexpr int x = 40; {y;} } \
{constexpr int x = 41; {y;} } \
{constexpr int x = 42; {y;} } \
{constexpr int x = 43; {y;} } \
{constexpr int x = 44; {y;} } \
{constexpr int x = 45; {y;} } \
{constexpr int x = 46; {y;} } \
{constexpr int x = 47; {y;} } \
{constexpr int x = 48; {y;} } \
{constexpr int x = 49; {y;} } \
{constexpr int x = 50; {y;} } \
{constexpr int x = 51; {y;} } \
{constexpr int x = 52; {y;} } \
{constexpr int x = 53; {y;} } \
{constexpr int x = 54; {y;} } \
{constexpr int x = 55; {y;} } \
{constexpr int x = 56; {y;} } \
{constexpr int x = 57; {y;} } \
{constexpr int x = 58; {y;} } \
{constexpr int x = 59; {y;} } \
{constexpr int x = 60; {y;} } \
{constexpr int x = 61; {y;} } \
{constexpr int x = 62; {y;} } \
{constexpr int x = 63; {y;} } \
}
template<int N>
static void ConstPrint(const char* name, uint64_t source[N])
{
std::stringstream ss;
ss << std::dec;
ss << "static constexpr uint64_t " << name << "[" << N << "] = { ";
ss << std::hex;
for (int i = 0; i < N; i++) {
ss << "0x" << source[i] << "ull";
if (i != N - 1) ss << ", ";
}
ss << "};\n";
ss << std::dec;
std::cout << ss.str();
}
static std::string _map(uint64_t value)
{
static std::string str(64 + 8, 'o');
for (uint64_t i = 0, c = 0; i < 64; i++)
{
uint64_t bitmask = (1ull) << i;
if ((bitmask & value) != 0) str[c++] = 'X';
else str[c++] = '.';
if ((i + 1) % 8 == 0) str[c++] = '\n';
}
return str;
}
//Reference
#include "Switch.hpp"
struct Switch_t {
static constexpr bool Supports_Template = true;
static inline constexpr std::string_view name = "Reference (Switch Lookup)";
static inline constexpr std::string_view sp_op = "none";
static inline constexpr std::string_view author = "Daniel Inf\x81hr (dangi12012)";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=78235&p=907362&hilit=espresso#p907362";
static void Prepare(uint64_t occ) {}
static constexpr uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Lookup_Switch::Queen(sq, occ); }
template <int sq> static constexpr uint64_t Queen(uint64_t occ) { return Chess_Lookup::Lookup_Switch::Queen<sq>(occ); }
static constexpr uint64_t Rook_Xray(int sq, uint64_t occ) { return Chess_Lookup::Lookup_Switch::Rook_Xray(sq, occ); }
static constexpr uint64_t Bish_Xray(int sq, uint64_t occ) { return Chess_Lookup::Lookup_Switch::Bishop_Xray(sq, occ); }
static constexpr uint64_t Size() { return Chess_Lookup::Lookup_Switch::Size; }
};
#if GeneticObstruction_
#include "GeneticObstructionDiff.hpp"
struct GeneticObstructionDiff_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Genetic Obstruction Difference";
static inline constexpr std::string_view author = "Daniel Inf\x81hr and Michael Hoffmann";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=79701";
static inline constexpr std::string_view sp_op = "countl_zero";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::GeneticObstructionDiff::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::GeneticObstructionDiff::Size; }
};
#else
Dummy(GeneticObstructionDiff_t);
#endif
#if GeneticObstructionV2_
#include "GeneticObstructionDiffV2.hpp"
struct GeneticObstructionDiffV2_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Genetic Obstruction Difference V2";
static inline constexpr std::string_view author = "Daniel Inf\x81hr";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=79701";
static inline constexpr std::string_view sp_op = "countl_zero";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::GeneticObstructionDiffV2::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::GeneticObstructionDiffV2::Size; }
};
#else
Dummy(GeneticObstructionDiffV2_t);
#endif
#if FoldingHash_
#include "FoldingHash.hpp"
struct FoldingHash_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "FoldingHash - 4x fancy magic";
static inline constexpr std::string_view author = "Daniel Inf\x81hr";
static inline constexpr std::string_view reference = "tbd";
static inline constexpr std::string_view sp_op = "none";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::FoldingHash::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::FoldingHash::Size; }
};
#else
Dummy(FoldingHash_t);
#endif
#if GaloisField_
#include "GaloisField.hpp"
struct GaloisField_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "GaloisField - AVX512";
static inline constexpr std::string_view author = "Daniel Inf\x81hr (dangi12012)";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=81335";
static inline constexpr std::string_view sp_op = "AVX512F_GFNI";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::GaloisField::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::GaloisField::Size; }
};
#else
Dummy(GaloisField_t);
#endif
#if Gigantua_
#include "Gigantua.hpp"
struct Gigantua_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Gigantua Rotation Algorithm";
static inline constexpr std::string_view author = "Daniel Inf\x81hr (dangi12012)";
static inline constexpr std::string_view reference = "https://www.talkchess.com/forum3/viewtopic.php?f=7&t=81707&sid=ec3532ea1ce1e8014d2b579b29fddd34";
static inline constexpr std::string_view sp_op = "AVX2 or AVX512 + GFNI";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Gigantua::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::Gigantua::Size; }
};
#else
Dummy(Gigantua_t);
#endif
#if Genetic8Ray_
#include "Genetic8Ray.hpp"
struct Genetic8Ray_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Genetic 8 Ray";
static inline constexpr std::string_view sp_op = "bswap";
static inline constexpr std::string_view author = "Daniel Inf\x81hr (dangi12012)";
static inline constexpr std::string_view reference = "Abstract C++ Syntax Tree Sifter (c) Daniel Infuehr";
static inline uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Genetic8Ray::Queen(sq, occ); }
static inline uint64_t Size() { return Chess_Lookup::Genetic8Ray::Size; }
};
#else
Dummy(Genetic8Ray_t);
#endif
#if AVXShift_
#include "AVXShift.hpp"
struct Loop_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "AVX Branchless Shift";
static inline constexpr std::string_view sp_op = "AVX2";
static inline constexpr std::string_view author = "Daniel Inf\x81hr (dangi12012)";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=79005&start=60";
static inline uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::AVXShift::Queen(sq, occ); }
static inline uint64_t Size() { return Chess_Lookup::AVXShift::Size; }
};
#else
Dummy(Loop_t);
#endif
#if Dumb7_
#include "Dumb7Fill.hpp"
struct Dumb7_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Dumb7 Fill";
static inline constexpr std::string_view author = "Gunnar Andersson";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/Dumb7Fill";
static inline constexpr std::string_view sp_op = "none";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Dumb7Fill::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::Dumb7Fill::Size; }
};
#else
Dummy(Dumb7_t);
#endif
#if Kogge_
#include "KoggeStone.hpp"
struct Kogge_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Kogge-Stone";
static inline constexpr std::string_view author = "Peter M. Kogge, Harold S. Stone";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/Kogge-Stone_Algorithm";
static inline constexpr std::string_view sp_op = "none";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::KoggeStone::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::KoggeStone::Size; }
};
#else
Dummy(Kogge_t);
#endif
#if Bob_
#include "Boblookup.hpp"
struct Bob_t {
static constexpr bool Supports_Template = true;
static inline constexpr std::string_view name = "Classical Bob-Mike";
static inline constexpr std::string_view author = "Robert Hyatt and Michael Sherwin";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/Classical_Approach";
static inline constexpr std::string_view sp_op = "countr_zero, countl_zero";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::BobLU::Queen(sq, occ); }
template <int sq> static uint64_t Queen(uint64_t occ) { return Chess_Lookup::BobLU::Queen<sq>(occ); }
static uint64_t Size() { return Chess_Lookup::BobLU::Size; }
};
#else
Dummy(Bob_t);
#endif
#if BobAdvanced_
#include "Boblookup_advanced.hpp"
struct BobAdvanced_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Advanced Bob-Mike";
static inline constexpr std::string_view author = "Michael Sherwin and Daniel Inf\x81hr";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=79078&start=50#p924653";
static inline constexpr std::string_view sp_op = "countr_zero, countl_zero";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::BobAdvanced::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::BobAdvanced::Size; }
};
#else
Dummy(BobAdvanced_);
#endif
#if Leorik_
#include "Leorik.hpp"
struct Leorik_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Leorik";
static inline constexpr std::string_view author = "Thomas Jahn (lithander)";
static inline constexpr std::string_view reference = "https://github.com/lithander/MinimalChessEngine";
static inline constexpr std::string_view sp_op = "countl_zero";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Leorik::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::Leorik::Size; }
};
#else
Dummy(Leorik_t);
#endif
#if LeorikNT_
#include "Leorik_IL.hpp"
struct LeorikNT_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Leorik Inline";
static inline constexpr std::string_view author = "Thomas Jahn (lithander)";
static inline constexpr std::string_view reference = "https://github.com/lithander/MinimalChessEngine";
static inline constexpr std::string_view sp_op = "countl_zero";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::LeorikIL::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::LeorikIL::Size; }
};
#else
Dummy(LeorikNT_t);
#endif
#if Hyper_
#include "Hyperchess.hpp"
struct Hyper_t {
static constexpr bool Supports_Template = true;
static inline constexpr std::string_view name = "HyperCube";
static inline constexpr std::string_view author = "Daniel Inf\x81hr (dangi12012)";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=79004&p=916723&hilit=hypercube#p916723";
static inline constexpr std::string_view sp_op = "none";
static inline void Prepare(uint64_t occ) { Chess_Lookup::Lookup_Hyper::Prepare(occ); }
static constexpr void Move(int from, int to) { Chess_Lookup::Lookup_Hyper::Move(from, to); }
static constexpr void Move_Take(int from, int to) { Chess_Lookup::Lookup_Hyper::Move_Take(from, to); }
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Lookup_Hyper::Queen(sq, occ); }
template <int sq> static uint64_t Queen(uint64_t occ) { return Chess_Lookup::Lookup_Hyper::Queen<sq>(occ); }
static uint64_t Rook_Xray(int sq, uint64_t occ) { return Chess_Lookup::Lookup_Hyper::Rook_Xray(sq); }
static uint64_t Bish_Xray(int sq, uint64_t occ) { return Chess_Lookup::Lookup_Hyper::Bishop_Xray(sq); }
static uint64_t Size() { return Chess_Lookup::Lookup_Hyper::Size; }
};
#else
Dummy(Hyper_t);
#endif
#if Pext_
#include "Pext.hpp"
struct Pext_t {
static constexpr bool Supports_Template = true;
static inline constexpr std::string_view name = "Pext constexpr";
static inline constexpr std::string_view author = "Zach Wegner";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/BMI2#PEXTBitboards";
static inline constexpr std::string_view sp_op = "pext_u64";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Lookup_Pext::Queen(sq, occ); }
template <int sq> static constexpr uint64_t Queen(uint64_t occ) { return Chess_Lookup::Lookup_Pext::Queen<sq>(occ); }
static uint64_t Size() { return Chess_Lookup::Lookup_Pext::Size; }
};
#else
Dummy(Pext_t);
#endif
#if SplitPext_
#include "SplitPext.hpp"
struct SplitPext_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Split Pext";
static inline constexpr std::string_view author = "Group Idea";
static inline constexpr std::string_view reference = "https://www.talkchess.com/forum3/viewtopic.php?f=7&t=79049&start=340";
static inline constexpr std::string_view sp_op = "pext_u64";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::SplitPext::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::SplitPext::Size; }
};
#else
Dummy(SplitPext_t);
#endif
#if PextEmu_
#include "Pext.hpp"
struct PextEmu_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Pext Emulated";
static inline constexpr std::string_view author = "Zach Wegner"; //Daniel Inführ
static inline constexpr std::string_view reference = "https://randombit.net/bitbashing/posts/haswell_bit_permutations.html";
static inline constexpr std::string_view sp_op = "none";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Lookup_Pext::Queen_Emulated(sq, occ); }
static uint64_t Size() { return Chess_Lookup::Lookup_Pext::Size; }
};
#else
Dummy(Pext_t);
#endif
#if Plain_
#include "Hash_Plain.hpp"
struct Plain_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Plain Magic BB";
static inline constexpr std::string_view author = "Lasse Hansen";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/Magic_Bitboards#Plain";
static inline constexpr std::string_view sp_op = "imul64";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Plain::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::Plain::Size; }
};
#else
Dummy(Plain_t);
#endif
#if HVar_
#include "Hash_Var.hpp"
struct HVar_t {
static constexpr bool Supports_Template = true;
static inline constexpr std::string_view name = "Fancy Magic BB - Variable shift";
static inline constexpr std::string_view author = "Pradu Kannan";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/Magic_Bitboards#Fancy";
static inline constexpr std::string_view sp_op = "imul64";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Var::Queen(sq, occ); }
template <int sq> static uint64_t Queen(uint64_t occ) { return Chess_Lookup::Var::Queen<sq>(occ); }
static uint64_t Size() { return Chess_Lookup::Var::Size; }
};
#else
Dummy(HVar_t);
#endif
#if CMagic_
#include "Correlationmagic.hpp"
struct CMagic_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Correlation Magic";
static inline constexpr std::string_view author = "Daniel Inf\x81hr";
static inline constexpr std::string_view reference = "https://www.talkchess.com/forum3/viewtopic.php?f=7&t=82224#p949688";
static inline constexpr std::string_view sp_op = "imul64";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Correlationmagic::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::Correlationmagic::Size; }
};
#else
Dummy(CMagic_t);
#endif
#if SMagic_
#include "Correlationmagic.hpp"
struct SMagic_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Spectral Magic";
static inline constexpr std::string_view author = "Daniel Inf\x81hr";
static inline constexpr std::string_view reference = "https://www.talkchess.com/forum3/viewtopic.php?f=7&t=82224#p949688";
static inline constexpr std::string_view sp_op = "none";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Correlationmagic::SpectralQueen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::Correlationmagic::Size; }
};
#else
Dummy(SMagic_t);
#endif
#if SMagic2_
#include "Spectralmagic.hpp"
struct SMagic2_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Spectral Magic Switched";
static inline constexpr std::string_view author = "Daniel Inf\x81hr";
static inline constexpr std::string_view reference = "https://www.talkchess.com/forum3/viewtopic.php?f=7&t=79005&start=160";
static inline constexpr std::string_view sp_op = "none";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::SpectralMagic::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::SpectralMagic::Size; }
};
#else
Dummy(SMagic2_t);
#endif
#if Fancy_
#include "Hash_Fancy.hpp"
struct Fancy_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Black Magic BB - Fixed shift";
static inline constexpr std::string_view author = "Onno Garms and Volker Annuss";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/Magic_Bitboards#Fixed_shift_Fancy";
static inline constexpr std::string_view sp_op = "imul64";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Fancy::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::Fancy::Size; }
};
#else
Dummy(Fancy_t);
#endif
#if Explode_
#include "Exploading.hpp"
struct Explode_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Exploding Bitboards";
static inline constexpr std::string_view author = "Harald L\x81\xE1 \ben\t"; //Harald Lüßen
static inline constexpr std::string_view reference = "http://www.open-aurec.com/wbforum/viewtopic.php?f=4&t=4523&start=80";
static inline constexpr std::string_view sp_op = "imul64";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::ExplodingBoard::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::ExplodingBoard::Size; }
};
#else
Dummy(Explode_t);
#endif
#if SBAMG_
#include "SBAMG.hpp"
struct SBAMG_t {
static constexpr bool Supports_Template = true;
static inline constexpr std::string_view name = "SBAMG o^(o-3cbn)";
static inline constexpr std::string_view author = "Syed Fahad";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?t=59845";
static inline constexpr std::string_view sp_op = "countl_zero, bswap";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::SBAMG::Queen(sq, occ); }
template <int sq> static uint64_t Queen(uint64_t occ) { return Chess_Lookup::SBAMG::Queen<sq>(occ); }
static uint64_t Size() { return Chess_Lookup::SBAMG::Size; }
};
#else
Dummy(SBAMG_t);
#endif
#if SBAMGNT_
#include "SBAMG_IL.hpp"
struct SBAMGNT_t {
static constexpr bool Supports_Template = true;
static inline constexpr std::string_view name = "SBAMG Inline";
static inline constexpr std::string_view author = "Syed Fahad and Daniel Inf\x81hr";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?t=59845";
static inline constexpr std::string_view sp_op = "countl_zero, bswap";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::SBAMGInline::Queen(sq, occ); }
template <int sq> static uint64_t Queen(uint64_t occ) { return Chess_Lookup::SBAMGInline::Queen<sq>(occ); }
static uint64_t Size() { return Chess_Lookup::SBAMGInline::Size; }
};
#else
Dummy(SBAMGNT_t);
#endif
#if BinaryNetwork_
#include "BinaryNeuralNetwork.hpp"
struct BinaryNetwork_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Binary Neural Network";
static inline constexpr std::string_view author = "Daniel Inf\x81hr (dangi12012)";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=79332";
static inline constexpr std::string_view sp_op = "pdep_u64, AVX2";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::BNN::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::BNN::Size; }
};
#else
Dummy(BinaryNetwork_t);
#endif
#if HypQsc_
#include "Hyperbola.hpp"
struct Hyperbola_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Hyperbola Quintessence o^(o-2r)";
static inline constexpr std::string_view author = "Ryan Mack";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/Hyperbola_Quintessence";
static inline constexpr std::string_view sp_op = "bswap";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::HyperbolaQsc::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::HyperbolaQsc::Size; }
};
#else
Dummy(Hyperbola_t);
#endif
#if HypQscNT_
#include "Hyperbola_IL.hpp"
struct HyperbolaNT_t {
static constexpr bool Supports_Template = true;
static inline constexpr std::string_view name = "Hyperbola Quintessence Inline";
static inline constexpr std::string_view author = "Ryan Mack";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/Hyperbola_Quintessence";
static inline constexpr std::string_view sp_op = "bswap";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::HyperbolaQscInline::Queen(sq, occ); }
template <int sq> static uint64_t Queen(uint64_t occ) { return Chess_Lookup::HyperbolaQscInline::Queen<sq>(occ); }
static uint64_t Size() { return Chess_Lookup::HyperbolaQscInline::Size; }
};
#else
Dummy(HyperbolaNT_t);
#endif
#if Rotate_
#include "Rotated.hpp"
struct Rotate_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Rotated Bitboards";
static inline constexpr std::string_view author = "Robert Hyatt";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/Rotated_Bitboards";
static inline constexpr std::string_view sp_op = "none";
static inline void Prepare(uint64_t occ) { Chess_Lookup::RotatedBB::Prepare(occ); }
static constexpr void Move(int from, int to) { Chess_Lookup::RotatedBB::Move(from, to); }
static constexpr void Move_Take(int from, int to) { Chess_Lookup::RotatedBB::Move_Take(from, to); }
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::RotatedBB::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::RotatedBB::Size; }
};
#else
Dummy(Rotate_t);
#endif
#if Arithm_
#include "SlideArithm.hpp"
struct Arithm_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Slide Arithmetic";
static inline constexpr std::string_view author = "Jakob Progsch and Daniel Inf\x81hr";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=78693&p=914767&hilit=SlideArithm#p914767";
static inline constexpr std::string_view sp_op = "bzhi_u64, blsmsk_u64";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::SlideArithm::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::SlideArithm::Size; }
};
#else
Dummy(Arithm_t);
#endif
#if Arithm_
#include "SlideArithm_IL.hpp"
struct ArithmNT_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Slide Arithmetic Inline";
static inline constexpr std::string_view author = "Jakob Progsch and Daniel Inf\x81hr";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=78693&p=914767&hilit=SlideArithm#p914767";
static inline constexpr std::string_view sp_op = "bzhi_u64, blsmsk_u64";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::SlideArithmInline::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::SlideArithmInline::Size; }
};
#else
Dummy(ArithmNT_t);
#endif
#if Kindergarten_
#include "Kindergarten.hpp"
struct Kindergarten_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Kindergarten";
static inline constexpr std::string_view author = "Urban Koistinen";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/Kindergarten_Bitboards";
static inline constexpr std::string_view sp_op = "imul64";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Kindergarten::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::Kindergarten::Size; }
};
#else
Dummy(Kindergarten_t);
#endif
#if Obstrd_
#include "ObstructionDiff.hpp"
struct Obstruct_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Obstruction Difference";
static inline constexpr std::string_view author = "Michael Hoffmann";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?t=29087";
static inline constexpr std::string_view sp_op = "countl_zero";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::ObstructionDiff::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::ObstructionDiff::Size; }
};
#else
Dummy(Obstruct_t);
#endif
#if ObstrdNT_
#include "ObstructionDiff_IL.hpp"
struct ObstructNT_t {
static constexpr bool Supports_Template = true;
static inline constexpr std::string_view name = "Obstruction Difference Inline";
static inline constexpr std::string_view author = "Michael Hoffmann";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?t=29087";
static inline constexpr std::string_view sp_op = "countl_zero";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::ObstructionDiffInline::Queen(sq, occ); }
template <int sq> static uint64_t Queen(uint64_t occ) { return Chess_Lookup::ObstructionDiffInline::Queen<sq>(occ); }
static uint64_t Size() { return Chess_Lookup::ObstructionDiffInline::Size; }
};
#else
Dummy(ObstructNT_t);
#endif
#if QBB_
#include "QBB.hpp"
struct QBB_t {
static constexpr bool Supports_Template = true;
static inline constexpr std::string_view name = "QBBEngine";
static inline constexpr std::string_view author = "Fabio Gobbato";
static inline constexpr std::string_view reference = "https://www.chessprogramming.org/QBBEngine";
static inline constexpr std::string_view sp_op = "countr_zero, countl_zero";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::QBB::Queen(sq, occ); }
template <int sq> static uint64_t Queen(uint64_t occ) { return Chess_Lookup::QBB::Queen<sq>(occ); }
static uint64_t Size() { return Chess_Lookup::QBB::Size; }
};
#else
Dummy(QBB_t);
#endif
#if GeneticQBB_
#include "GeneticQBB.hpp"
struct GeneticQBB_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "QBBEngine - Shifted Mask";
static inline constexpr std::string_view author = "Fabio Gobbato";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=79005&start=90#p924623";
static inline constexpr std::string_view sp_op = "countr_zero, countl_zero";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::GeneticQBB::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::GeneticQBB::Size; }
};
#else
Dummy(GeneticQBB_t);
#endif
#if Sissy_
#include "Sissy.hpp"
struct Sissy_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "SISSY Bitboards";
static inline constexpr std::string_view author = "Michael Sherwin";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=73083";
static inline constexpr std::string_view sp_op = "none";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::SISSY::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::SISSY::Size; }
};
#else
Dummy(Sissy_t);
#endif
#if KGSSB_
#include "KindergartenSuperSissyBoard.hpp"
struct Kgssb_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Kindergarten Super SISSY Bitboards";
static inline constexpr std::string_view author = "Michael Sherwin";
static inline constexpr std::string_view reference = "https://www.talkchess.com/forum3/viewtopic.php?f=7&t=81234&start=30";
static inline constexpr std::string_view sp_op = "imul64";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::KGSSB::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::KGSSB::Size; }
};
#else
Dummy(Kgssb_t);
#endif
#if Rotate_
#include "Bitrotation.hpp"
struct Bitrotate_t {
static constexpr bool Supports_Template = false;
static inline constexpr std::string_view name = "Bitrotation";
static inline constexpr std::string_view author = "Daniel Inf\x81hr (dangi12012)";
static inline constexpr std::string_view reference = "http://www.talkchess.com/forum3/viewtopic.php?f=7&t=79078&start=20";
static inline constexpr std::string_view sp_op = "ReverseBits";
static uint64_t Queen(int sq, uint64_t occ) { return Chess_Lookup::Bitrotation::Queen(sq, occ); }
static uint64_t Size() { return Chess_Lookup::Bitrotation::Size; }
};
#else
Dummy(Bitrotate_t);
#endif
// Todo - publish pext outperformer X(Gigantua_t);
#define TestAlgo(X) \
X(CMagic_t) \
X(SMagic_t) \
X(SMagic2_t) \
X(SBAMG_t) \
X(SBAMGNT_t) \
X(GaloisField_t) \
X(Gigantua_t) \
X(Hyperbola_t); \
X(HyperbolaNT_t) \
X(Genetic8Ray_t) \
X(Bitrotate_t); \
X(BinaryNetwork_t); \
X(Explode_t); \
X(Switch_t); \
X(Loop_t); \
X(PextEmu_t); \
X(Dumb7_t); \
X(Kogge_t); \
X(Rotate_t); \
X(QBB_t); \
X(GeneticQBB_t); \
X(Bob_t); \
X(BobAdvanced_t); \
X(Leorik_t); \
X(LeorikNT_t); \
X(Obstruct_t); \
X(ObstructNT_t); \
X(GeneticObstructionDiff_t) \
X(GeneticObstructionDiffV2_t) \
X(Arithm_t); \
X(ArithmNT_t); \
X(Kindergarten_t) \
X(Sissy_t); \
X(Kgssb_t); \
X(HVar_t); \
X(FoldingHash_t) \
X(Plain_t); \
X(Fancy_t); \
X(Pext_t); \
X(SplitPext_t); \
X(Hyper_t);
#define ExportAlgo(X) extern "C" __declspec(dllexport) uint64_t __cdecl X##_Queen(int sq, uint64_t occ) { return X::Queen(sq, occ); }
TestAlgo(ExportAlgo);
#define IsCorrect(X) if constexpr (X::name != "dummy") {if (X::Queen(i, occ) != atk_ref) { std::cout << X::name <<"failed. Reference:\n"<<"Occupy: "<<occ<<"\n"<<_map(occ)<<"\nSolution:\n"<<_map(atk_ref) <<"\nError:\n"<<_map(X::Queen(i, occ)); return false; }}
//Initialize and verify all algorithms
bool VerifyInit() {
uint64_t occ = 0;
#if Sissy_
//Todo: Constexpr initializer
Chess_Lookup::SISSY::Init();
#endif
#if PextSparse_
Chess_Lookup::PextSparse::Init();
#endif
#if Gigantua_
Chess_Lookup::Gigantua::Init();