-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathERoc.cpp
More file actions
7811 lines (6093 loc) · 275 KB
/
ERoc.cpp
File metadata and controls
7811 lines (6093 loc) · 275 KB
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
/// Roc and Platform
#include "Base/Platform.h"
#include <array>
#include "Chess/Chess.h"
#include "Chess/Bit.h"
#include "Chess/Pack.h"
#include "Chess/Array.h"
#include "Chess/Board.h"
#include "Chess/Score.h"
#include "Chess/Killer.h"
#include "Chess/Material.h"
#include "Chess/Eval.h"
INLINE constexpr packed_t EPack(sint16 op, sint16 eg)
{
return Pack((11 * op + eg) / 12, (op + eg) / 2, (op + 11 * eg) / 12, 0);
}
using std::array;
#pragma warning(disable: 4996)
// config
#define USE_NNUE 0
#define USE_AVX2 1
/// types.h
#include <cassert>
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <memory>
#include <intrin.h>
#include <chrono>
#include <thread>
#include <iostream>
#undef assert
#define assert(x)
constexpr int FALSE = 0, TRUE = 1;
enum { MG, EG, N_PHASES };
constexpr int OP_PHASE = 22, MG_PHASE = 12, EG_PHASE = 2;
enum { WHITE, BLACK, N_COLORS };
enum { PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING, N_PIECES };
constexpr int MAX_PLY = 128, MAX_MOVES = 256;
constexpr inline int ColoredPiece(int c, int p) { return c | (p << 2); }
constexpr int WHITE_PAWN = ColoredPiece(WHITE, PAWN);
constexpr int BLACK_PAWN = ColoredPiece(BLACK, PAWN);
constexpr int WHITE_KNIGHT = ColoredPiece(WHITE, KNIGHT);
constexpr int BLACK_KNIGHT = ColoredPiece(BLACK, KNIGHT);
constexpr int WHITE_BISHOP = ColoredPiece(WHITE, BISHOP);
constexpr int BLACK_BISHOP = ColoredPiece(BLACK, BISHOP);
constexpr int WHITE_ROOK = ColoredPiece(WHITE, ROOK);
constexpr int BLACK_ROOK = ColoredPiece(BLACK, ROOK);
constexpr int WHITE_QUEEN = ColoredPiece(WHITE, QUEEN);
constexpr int BLACK_QUEEN = ColoredPiece(BLACK, QUEEN);
constexpr int WHITE_KING = ColoredPiece(WHITE, KING);
constexpr int BLACK_KING = ColoredPiece(BLACK, KING);
constexpr int EMPTY = 26;
constexpr array<int, 32> MakeMatIndices()
{
array<int, 32> retval{};
retval[WHITE_PAWN] = MatCodeWP;
retval[BLACK_PAWN] = MatCodeBP;
retval[WHITE_KNIGHT] = MatCodeWN;
retval[BLACK_KNIGHT] = MatCodeBN;
retval[WHITE_BISHOP] = MatCodeWL;
retval[BLACK_BISHOP] = MatCodeBL;
retval[WHITE_ROOK] = MatCodeWR;
retval[BLACK_ROOK] = MatCodeBR;
retval[WHITE_QUEEN] = MatCodeWQ;
retval[BLACK_QUEEN] = MatCodeBQ;
return retval;
}
constexpr array<int, 32> MatIndices = MakeMatIndices();
constexpr int MATE_IN_MAX = 32000, MATE = MATE_IN_MAX + MAX_PLY;
constexpr int TBWIN_IN_MAX = 30976, TBWIN = TBWIN_IN_MAX + MAX_PLY;
constexpr int VALUE_NONE = MATE + 1;
constexpr int N_RANKS = 8, N_FILES = 8, N_SQUARES = N_RANKS * N_FILES;
constexpr inline int TypeOf(int piece) { return piece / 4; }
constexpr inline int ColorOf(int piece) { return piece % 4; }
constexpr inline int IsPiece(int piece) { return piece >= 0 && TypeOf(piece) < N_PIECES && ColorOf(piece) < N_COLORS; }
constexpr inline int makePiece(int type, int colour) {
assert(0 <= type && type < N_PIECES);
assert(0 <= colour && colour <= N_COLORS);
return ColoredPiece(colour, type);
}
// Renamings, currently for move ordering
constexpr int N_CONTINUATION = 2;
using KillerMoves = array<uint16_t, N_KILLER>;
using KillerTable = array<KillerMoves, MAX_PLY + 1>;
using CounterMoveTable = array<array<array<uint16_t, N_SQUARES>, N_PIECES>, N_COLORS>;
using HistoryTable = array<array<array<array<array<score_t, N_SQUARES>, N_SQUARES>, 2>, 2>, N_COLORS>;
using CaptureHistoryTable = array<array<array<array<array<score_t, N_PIECES - 1>, N_SQUARES>, 2>, 2>, N_PIECES>;
using ContinuationTable = array<array<array<array<array<array<score_t, N_SQUARES>, N_PIECES>, N_CONTINUATION>, N_SQUARES>, N_PIECES>, 2>;
constexpr inline packed_t MakeScore(score_t mg, score_t eg) { return EPack(mg, eg); }
constexpr inline score_t ScoreOP(packed_t s) { return Pick16<1>(s); }
constexpr inline score_t ScoreMG(packed_t s) { return Pick16<2>(s); }
constexpr inline score_t ScoreEG(packed_t s) { return Pick16<3>(s); }
// Trivial alignment macros
#define ALIGN64 alignas(64)
#ifdef _MSC_VER
#define INLINE __forceinline
#define NOINLINE __declspec(noinline)
#define strtok_r strtok_s
void Prefetch1(const char* p)
{
_mm_prefetch(p, _MM_HINT_T0);
}
template<int N> void Prefetch(const void* q)
{
const char* p = reinterpret_cast<const char*>(q);
//p -= reinterpret_cast<size_t>(p) & 63;
for (int ii = 0; ii < N; ++ii)
Prefetch1(p + 64 * ii);
}
#else
#define INLINE static inline __attribute__((always_inline))
#define NOINLINE __attribute__((noinline))
#endif
/// bitboards.h
constexpr uint64
LONG_DIAGONALS = 0x8142241818244281ull,
CENTER_SQUARES = 0x0000001818000000ull,
CENTER_BIG = 0x00003C3C3C3C0000ull,
LEFT_FLANK = File[0] | File[1] | File[2] | File[3],
RIGHT_FLANK = File[4] | File[5] | File[6] | File[7],
PROMOTION_RANKS = Line[0] | Line[7];
constexpr array<int, 8> MIRROR_FILE = { 0, 1, 2, 3, 3, 2, 1, 0 };
/// bitboards.c
constexpr int mirrorFile(int file) {
assert(0 <= file && file < N_FILES);
return MIRROR_FILE[file];
}
constexpr int rankOf(int sq) {
assert(0 <= sq && sq < N_SQUARES);
return RankOf(sq);
}
constexpr int square(int rank, int file) {
assert(0 <= rank && rank < N_RANKS);
assert(0 <= file && file < N_FILES);
return rank * N_FILES + file;
}
template<int US> constexpr int RelativeSquare(int sq)
{
static_assert(0 <= US && US < N_COLORS);
assert(0 <= sq && sq < N_SQUARES);
return square(OwnRankOf<US>(sq), FileOf(sq));
}
INLINE int relativeSquare(int colour, int sq)
{
return (colour == WHITE ? RelativeSquare<WHITE> : RelativeSquare<BLACK>)(sq);
}
template<int US> constexpr int RelativeSquare32(int sq)
{
static_assert(0 <= US && US < N_COLORS);
assert(0 <= sq && sq < N_SQUARES);
return 4 * OwnRankOf<US>(sq) + mirrorFile(FileOf(sq));
}
constexpr void setBit(uint64* bb, int i) {
assert(!HasBit(*bb, i));
*bb ^= Bit(i);
}
uint64 squaresOfMatchingColour(int sq) {
assert(0 <= sq && sq < N_SQUARES);
return HasBit(LightArea, sq) ? LightArea : DarkArea;
}
int popcount(uint64 bb) {
#ifdef _MSC_VER
return static_cast<int>(_mm_popcnt_u64(bb));
#else
return __builtin_popcountll(bb);
#endif
}
int frontmost(int colour, uint64 bb) {
assert(0 <= colour && colour < N_COLORS);
return colour == WHITE ? msb(bb) : lsb(bb);
}
int backmost(int colour, uint64 bb) {
assert(0 <= colour && colour < N_COLORS);
return colour == WHITE ? lsb(bb) : msb(bb);
}
inline int poplsb(uint64* bb) {
int retval = lsb(*bb);
*bb &= *bb - 1;
return retval;
}
int popmsb(uint64* bb) {
int retval = msb(*bb);
*bb ^= 1ull << retval;
return retval;
}
void printBitboard(uint64 bb)
{
for (int rank = 7; rank >= 0; rank--) {
char line[] = ". . . . . . . .";
for (int file = 0; file < N_FILES; file++)
if (HasBit(bb, square(rank, file)))
line[2 * file] = 'X';
printf("%s\n", line);
}
printf("\n");
}
/// PSQT from evaluate.c
/* Piece Square Evaluation Terms */
#define S MakeScore
using PSQVals = array<packed_t, N_SQUARES>;
constexpr PSQVals PawnPSQT = {
S(0, 0), S(0, 0), S(0, 0), S(0, 0), S(0, 0), S(0, 0), S(0, 0), S(0, 0),
S(-13, 7), S(-4, 0), S(1, 4), S(6, 1), S(3, 10), S(-9, 4), S(-9, 3), S(-16, 7),
S(-21, 5), S(-17, 6), S(-1, -6), S(12, -14), S(8, -10), S(-4, -5), S(-15, 7), S(-24, 11),
S(-14, 16), S(-21, 17), S(9, -10), S(10, -24), S(4, -22), S(4, -10), S(-20, 17), S(-17, 18),
S(-15, 18), S(-18, 11), S(-16, -8), S(4, -30), S(-2, -24), S(-18, -9), S(-23, 13), S(-17, 21),
S(-20, 48), S(-9, 44), S(1, 31), S(17, -9), S(36, -6), S(-9, 31), S(-6, 45), S(-23, 49),
S(-33, -70), S(-66, -9), S(-16, -22), S(65, -23), S(41, -18), S(39, -14), S(-47, 4), S(-62, -51),
S(0, 0), S(0, 0), S(0, 0), S(0, 0), S(0, 0), S(0, 0), S(0, 0), S(0, 0),
};
constexpr PSQVals KnightPSQT = {
S(-31, -38), S(-6, -24), S(-20, -22), S(-16, -1), S(-11, -1), S(-22, -19), S(-8, -20), S(-41, -30),
S(1, -5), S(-11, 3), S(-6, -19), S(-1, -2), S(0, 0), S(-9, -16), S(-8, -3), S(-6, 1),
S(7, -21), S(8, -5), S(7, 2), S(10, 19), S(10, 19), S(4, 2), S(8, -4), S(3, -19),
S(16, 21), S(17, 30), S(23, 41), S(27, 50), S(24, 53), S(23, 41), S(19, 28), S(13, 26),
S(13, 30), S(23, 30), S(37, 51), S(30, 70), S(26, 67), S(38, 50), S(22, 33), S(14, 28),
S(-24, 25), S(-5, 37), S(25, 56), S(22, 60), S(27, 55), S(29, 55), S(-1, 32), S(-19, 25),
S(13, -2), S(-11, 18), S(27, -2), S(37, 24), S(41, 24), S(40, -7), S(-13, 16), S(2, -2),
S(-167, -5), S(-91, 12), S(-117, 41), S(-38, 17), S(-18, 19), S(-105, 48), S(-119, 24), S(-165, -17),
};
constexpr PSQVals BishopPSQT = {
S(5, -21), S(1, 1), S(-1, 5), S(1, 5), S(2, 8), S(-6, -2), S(0, 1), S(4, -25),
S(26, -17), S(2, -31), S(15, -2), S(8, 8), S(8, 8), S(13, -3), S(9, -31), S(26, -29),
S(9, 3), S(22, 9), S(-5, -3), S(18, 19), S(17, 20), S(-5, -6), S(20, 4), S(15, 8),
S(0, 12), S(10, 17), S(17, 32), S(20, 32), S(24, 34), S(12, 30), S(15, 17), S(0, 14),
S(-20, 34), S(13, 31), S(1, 38), S(21, 45), S(12, 46), S(6, 38), S(13, 33), S(-14, 37),
S(-13, 31), S(-11, 45), S(-7, 23), S(2, 40), S(8, 38), S(-21, 34), S(-5, 46), S(-9, 35),
S(-59, 38), S(-49, 22), S(-13, 30), S(-35, 36), S(-33, 36), S(-13, 33), S(-68, 21), S(-55, 35),
S(-66, 18), S(-65, 36), S(-123, 48), S(-107, 56), S(-112, 53), S(-97, 43), S(-33, 22), S(-74, 15),
};
constexpr PSQVals RookPSQT = {
S(-26, -1), S(-21, 3), S(-14, 4), S(-6, -4), S(-5, -4), S(-10, 3), S(-13, -2), S(-22, -14),
S(-70, 5), S(-25, -10), S(-18, -7), S(-11, -11), S(-9, -13), S(-15, -15), S(-15, -17), S(-77, 3),
S(-39, 3), S(-16, 14), S(-25, 9), S(-14, 2), S(-12, 3), S(-25, 8), S(-4, 9), S(-39, 1),
S(-32, 24), S(-21, 36), S(-21, 36), S(-5, 26), S(-8, 27), S(-19, 34), S(-13, 33), S(-30, 24),
S(-22, 46), S(4, 38), S(16, 38), S(35, 30), S(33, 32), S(10, 36), S(17, 31), S(-14, 43),
S(-33, 60), S(17, 41), S(0, 54), S(33, 36), S(29, 35), S(3, 52), S(33, 32), S(-26, 56),
S(-18, 41), S(-24, 47), S(-1, 38), S(15, 38), S(14, 37), S(-2, 36), S(-24, 49), S(-12, 38),
S(33, 55), S(24, 63), S(-1, 73), S(9, 66), S(10, 67), S(0, 69), S(34, 59), S(37, 56),
};
constexpr PSQVals QueenPSQT = {
S(20, -34), S(4, -26), S(9, -34), S(17, -16), S(18, -18), S(14, -46), S(9, -28), S(22, -44),
S(6, -15), S(15, -22), S(22, -42), S(13, 2), S(17, 0), S(22, -49), S(18, -29), S(3, -18),
S(6, -1), S(21, 7), S(5, 35), S(0, 34), S(2, 34), S(5, 37), S(24, 9), S(13, -15),
S(9, 17), S(12, 46), S(-6, 59), S(-19, 109), S(-17, 106), S(-4, 57), S(18, 48), S(8, 33),
S(-10, 42), S(-8, 79), S(-19, 66), S(-32, 121), S(-32, 127), S(-23, 80), S(-8, 95), S(-10, 68),
S(-28, 56), S(-23, 50), S(-33, 66), S(-18, 70), S(-17, 71), S(-19, 63), S(-18, 65), S(-28, 76),
S(-16, 61), S(-72, 108), S(-19, 65), S(-52, 114), S(-54, 120), S(-14, 59), S(-69, 116), S(-11, 73),
S(8, 43), S(19, 47), S(0, 79), S(3, 78), S(-3, 89), S(13, 65), S(18, 79), S(21, 56),
};
constexpr PSQVals KingPSQT = {
S(87, -77), S(67, -49), S(4, -7), S(-9, -26), S(-10, -27), S(-8, -1), S(57, -50), S(79, -82),
S(35, 3), S(-27, -3), S(-41, 16), S(-89, 29), S(-64, 26), S(-64, 28), S(-25, -3), S(30, -4),
S(-44, -19), S(-16, -19), S(28, 7), S(0, 35), S(18, 32), S(31, 9), S(-13, -18), S(-36, -13),
S(-48, -44), S(98, -39), S(71, 12), S(-22, 45), S(12, 41), S(79, 10), S(115, -34), S(-59, -38),
S(-6, -10), S(95, -39), S(39, 14), S(-49, 18), S(-27, 19), S(35, 14), S(81, -34), S(-50, -13),
S(24, -39), S(123, -22), S(105, -1), S(-22, -21), S(-39, -20), S(74, -15), S(100, -23), S(-17, -49),
S(0, -98), S(28, -21), S(7, -18), S(-3, -41), S(-57, -39), S(12, -26), S(22, -24), S(-15,-119),
S(-16,-153), S(49, -94), S(-21, -73), S(-19, -32), S(-51, -55), S(-42, -62), S(53, -93), S(-58,-133),
};
/* Material Value Evaluation Terms */
constexpr packed_t PawnValue = S(82, 144);
constexpr packed_t KnightValue = S(426, 475);
constexpr packed_t BishopValue = S(441, 510);
constexpr packed_t RookValue = S(627, 803);
constexpr packed_t QueenValue = S(1292, 1623);
constexpr packed_t KingValue = S(0, 0);
#undef S
constexpr PSQVals NullPSQT = make_array<64>([](int) { return packed_t(0); });
constexpr array<PSQVals, 32> PSQT =
{
make_array<64>([&](int sq) { return PawnValue + PawnPSQT[RelativeSquare<WHITE>(sq)]; }),
make_array<64>([&](int sq) { return -PawnValue - PawnPSQT[RelativeSquare<BLACK>(sq)]; }),
NullPSQT,
NullPSQT,
make_array<64>([&](int sq) { return KnightValue + KnightPSQT[RelativeSquare<WHITE>(sq)]; }),
make_array<64>([&](int sq) { return -KnightValue - KnightPSQT[RelativeSquare<BLACK>(sq)]; }),
NullPSQT,
NullPSQT,
make_array<64>([&](int sq) { return BishopValue + BishopPSQT[RelativeSquare<WHITE>(sq)]; }),
make_array<64>([&](int sq) { return -BishopValue - BishopPSQT[RelativeSquare<BLACK>(sq)]; }),
NullPSQT,
NullPSQT,
make_array<64>([&](int sq) { return RookValue + RookPSQT[RelativeSquare<WHITE>(sq)]; }),
make_array<64>([&](int sq) { return -RookValue - RookPSQT[RelativeSquare<BLACK>(sq)]; }),
NullPSQT,
NullPSQT,
make_array<64>([&](int sq) { return QueenValue + QueenPSQT[RelativeSquare<WHITE>(sq)]; }),
make_array<64>([&](int sq) { return -QueenValue - QueenPSQT[RelativeSquare<BLACK>(sq)]; }),
NullPSQT,
NullPSQT,
make_array<64>([&](int sq) { return KingValue + KingPSQT[RelativeSquare<WHITE>(sq)]; }),
make_array<64>([&](int sq) { return -KingValue - KingPSQT[RelativeSquare<BLACK>(sq)]; }),
NullPSQT,
NullPSQT,
NullPSQT,
NullPSQT,
NullPSQT,
NullPSQT,
NullPSQT,
NullPSQT,
NullPSQT,
NullPSQT
};
/// zobrist.c
array<array<uint64, N_SQUARES>, 32> ZobristKeys;
array<uint64, N_FILES> ZobristEnpassKeys;
array<uint64, N_SQUARES> ZobristCastleKeys;
uint64 ZobristTurnKey;
uint64 rand64()
{
// http://vigna.di.unimi.it/ftp/papers/xorshift.pdf
static uint64 seed = 1070372ull;
seed ^= seed >> 12;
seed ^= seed << 25;
seed ^= seed >> 27;
return seed * 2685821657736338717ull;
}
void initZobrist()
{
// Init the main Zobrist keys for all pieces
for (int piece = PAWN; piece <= KING; piece++)
for (int sq = 0; sq < N_SQUARES; sq++)
for (int colour = WHITE; colour <= BLACK; colour++)
ZobristKeys[makePiece(piece, colour)][sq] = rand64();
// Init the Zobrist keys for each enpass file
for (int file = 0; file < N_FILES; file++)
ZobristEnpassKeys[file] = rand64();
// Init the Zobrist keys for each castle rook
for (int sq = 0; sq < N_SQUARES; sq++)
ZobristCastleKeys[sq] = rand64();
// Init the Zobrist key for side to move
ZobristTurnKey = rand64();
}
/// move.h
constexpr uint16_t
NONE_MOVE = 0, NULL_MOVE = 11,
NORMAL_MOVE = 0 << 12, CASTLE_MOVE = 1 << 12,
ENPASS_MOVE = 2 << 12, PROMOTION_MOVE = 3 << 12,
PROMOTE_TO_KNIGHT = 0 << 14, PROMOTE_TO_BISHOP = 1 << 14,
PROMOTE_TO_ROOK = 2 << 14, PROMOTE_TO_QUEEN = 3 << 14,
KNIGHT_PROMO_MOVE = PROMOTION_MOVE | PROMOTE_TO_KNIGHT,
BISHOP_PROMO_MOVE = PROMOTION_MOVE | PROMOTE_TO_BISHOP,
ROOK_PROMO_MOVE = PROMOTION_MOVE | PROMOTE_TO_ROOK,
QUEEN_PROMO_MOVE = PROMOTION_MOVE | PROMOTE_TO_QUEEN
;
inline int MoveFrom(int move) { return ((move) >> 0) & 63; }
inline int MoveTo(int move) { return ((move) >> 6) & 63; }
inline int MoveType(int move) { return (move) & (3 << 12); }
inline int MovePromoType(int move) { return (move) & (3 << 14); }
inline int MovePromoPiece(int move) { return 1 + ((move) >> 14); }
inline int MoveMake(int from, int to, int flag) { return from | (to << 6) | flag; }
constexpr array<const char*, N_COLORS> PieceLabel = { "PNBRQK", "pnbrqk" };
inline int castleKingTo(int king, int rook) {
return square(rankOf(king), (rook > king) ? 6 : 2);
}
inline int castleRookTo(int king, int rook) {
return square(rankOf(king), (rook > king) ? 5 : 3);
}
void squareToString(int sq, char* str)
{
// Helper for writing the enpass square, as well as for converting
// a move into long algabraic notation. When there is not an enpass
// square we will output a "-" as expected for a FEN
assert(-1 <= sq && sq < N_SQUARES);
if (sq == -1)
*str++ = '-';
else {
*str++ = FileOf(sq) + 'a';
*str++ = rankOf(sq) + '1';
}
*str++ = '\0';
}
void moveToString(uint16_t move, char* str, int chess960)
{
int from = MoveFrom(move), to = MoveTo(move);
// FRC reports using KxR notation, but standard does not
if (MoveType(move) == CASTLE_MOVE && !chess960)
to = castleKingTo(from, to);
// Encode squares (Long Algebraic Notation)
squareToString(from, &str[0]);
squareToString(to, &str[2]);
// Add promotion piece label (Uppercase)
if (MoveType(move) == PROMOTION_MOVE) {
str[4] = PieceLabel[BLACK][MovePromoPiece(move)];
str[5] = '\0';
}
}
void printMove(uint16_t move, int chess960) {
char str[6]; moveToString(move, str, chess960);
printf("%s\n", str);
}
/// history.h
constexpr int HistoryDivisor = 16384;
/// movepicker.h
enum { NORMAL_PICKER, NOISY_PICKER };
enum {
STAGE_TABLE,
STAGE_GENERATE_NOISY, STAGE_GOOD_NOISY,
STAGE_GENERATE_KILLER, STAGE_KILLER,
STAGE_COUNTER_MOVE,
STAGE_GENERATE_QUIET, STAGE_QUIET,
STAGE_BAD_NOISY,
STAGE_DONE,
};
/// timeman.h
/// limits from uci.h
struct Limits {
double start, time, inc, mtg, timeLimit;
int limitedByNone, limitedByTime, limitedBySelf;
int limitedByDepth, limitedByMoves, limitedByNodes;
int multiPV, depthLimit; uint64 nodeLimit;
uint16_t searchMoves[MAX_MOVES], excludedMoves[MAX_MOVES];
};
struct TimeManager {
int pv_stability;
double start_time, ideal_usage, max_usage;
array<uint64, 0x1000> nodes;
};
/// search.h
struct PVariation {
int length, score;
uint16_t line[MAX_PLY];
};
constexpr int WindowDepth = 5;
constexpr int WindowSize = 10;
constexpr int WindowTimerMS = 2500;
constexpr int CurrmoveTimerMS = 2500;
constexpr int TTResearchMargin = 128;
constexpr int BetaPruningDepth = 8;
constexpr int BetaMargin = 75;
constexpr int AlphaPruningDepth = 5;
constexpr int AlphaMargin = 3000;
constexpr int NullMovePruningDepth = 2;
constexpr int ProbCutDepth = 5;
constexpr int ProbCutMargin = 100;
constexpr int FutilityPruningDepth = 8;
constexpr int FutilityMarginBase = 92;
constexpr int FutilityMarginPerDepth = 59;
constexpr int FutilityMarginNoHistory = 158;
constexpr array<int, 2> FutilityPruningHistoryLimit = { 12000, 6000 };
constexpr array<int, 2> ContinuationPruningDepth = { 3, 2 };
constexpr array<int, 2> ContinuationPruningHistoryLimit = { -1000, -2500 };
constexpr int LateMovePruningDepth = 8;
constexpr int SEEPruningDepth = 9;
constexpr int SEEQuietMargin = -64;
constexpr int SEENoisyMargin = -19;
constexpr int SEEPieceValues[] = {
100, 450, 450, 675,
1300, 0, 0, 0,
};
constexpr int QSSeeMargin = 110;
constexpr int QSDeltaMargin = 150;
/// state.h
struct Thread;
struct Board_
{
array<uint8, N_SQUARES> at_;
array<uint64, 3> colors_;
array<uint64, 8> pieces_;
INLINE uint64 Pawns() const { return pieces_[PAWN]; }
INLINE uint64& Pawns() { return pieces_[PAWN]; }
INLINE uint64 Pawns(int me) const { return pieces_[PAWN] & colors_[me]; }
INLINE uint64 Knights() const { return pieces_[KNIGHT]; }
INLINE uint64& Knights() { return pieces_[KNIGHT]; }
INLINE uint64 Knights(int me) const { return pieces_[KNIGHT] & colors_[me]; }
INLINE uint64 Bishops() const { return pieces_[BISHOP]; }
INLINE uint64& Bishops() { return pieces_[BISHOP]; }
INLINE uint64 Bishops(int me) const { return pieces_[BISHOP] & colors_[me]; }
INLINE uint64 Rooks() const { return pieces_[ROOK]; }
INLINE uint64& Rooks() { return pieces_[ROOK]; }
INLINE uint64 Rooks(int me) const { return pieces_[ROOK] & colors_[me]; }
INLINE uint64 Queens() const { return pieces_[QUEEN]; }
INLINE uint64& Queens() { return pieces_[QUEEN]; }
INLINE uint64 Queens(int me) const { return pieces_[QUEEN] & colors_[me]; }
INLINE uint64 Kings() const { return pieces_[KING]; }
INLINE uint64& Kings() { return pieces_[KING]; }
INLINE uint64 Kings(int me) const { return pieces_[KING] & colors_[me]; }
};
struct State
{
Board_ board_;
uint8_t castleMasks[N_SQUARES];
uint64 hash, pkhash, kingAttackers, threats;
uint64 castleRooks;
packed_t psqtmat;
int turn, epSquare, halfMoveCounter, fullMoveCounter;
int numMoves, chess960, matIndex;
uint64 history[MAX_MOVES]; // should be MAX_PLY + 100?
Thread* thread;
};
struct Undo {
uint64 hash, pkhash, kingAttackers, threats, castleRooks;
packed_t psqtmat;
int epSquare, halfMoveCounter, capturePiece, matIndex;
};
/// attacks.h
struct Magic {
uint64 magic;
uint64 mask;
uint64 shift;
uint64* offset;
};
// needed for Pyrrhic
inline uint64 pawnAttacks(int colour, int sq) { return PAtt[colour][sq]; }
inline uint64 knightAttacks(int sq) { return NAtt[sq]; }
uint64 bishopAttacks(int sq, uint64 occupied);
uint64 rookAttacks(int sq, uint64 occupied);
uint64 queenAttacks(int sq, uint64 occupied);
inline uint64 kingAttacks(int sq) { return KAtt[sq]; }
constexpr array<uint64, N_SQUARES> RookMagics = {
0xA180022080400230ull, 0x0040100040022000ull, 0x0080088020001002ull, 0x0080080280841000ull,
0x4200042010460008ull, 0x04800A0003040080ull, 0x0400110082041008ull, 0x008000A041000880ull,
0x10138001A080C010ull, 0x0000804008200480ull, 0x00010011012000C0ull, 0x0022004128102200ull,
0x000200081201200Cull, 0x202A001048460004ull, 0x0081000100420004ull, 0x4000800380004500ull,
0x0000208002904001ull, 0x0090004040026008ull, 0x0208808010002001ull, 0x2002020020704940ull,
0x8048010008110005ull, 0x6820808004002200ull, 0x0A80040008023011ull, 0x00B1460000811044ull,
0x4204400080008EA0ull, 0xB002400180200184ull, 0x2020200080100380ull, 0x0010080080100080ull,
0x2204080080800400ull, 0x0000A40080360080ull, 0x02040604002810B1ull, 0x008C218600004104ull,
0x8180004000402000ull, 0x488C402000401001ull, 0x4018A00080801004ull, 0x1230002105001008ull,
0x8904800800800400ull, 0x0042000C42003810ull, 0x008408110400B012ull, 0x0018086182000401ull,
0x2240088020C28000ull, 0x001001201040C004ull, 0x0A02008010420020ull, 0x0010003009010060ull,
0x0004008008008014ull, 0x0080020004008080ull, 0x0282020001008080ull, 0x50000181204A0004ull,
0x48FFFE99FECFAA00ull, 0x48FFFE99FECFAA00ull, 0x497FFFADFF9C2E00ull, 0x613FFFDDFFCE9200ull,
0xFFFFFFE9FFE7CE00ull, 0xFFFFFFF5FFF3E600ull, 0x0010301802830400ull, 0x510FFFF5F63C96A0ull,
0xEBFFFFB9FF9FC526ull, 0x61FFFEDDFEEDAEAEull, 0x53BFFFEDFFDEB1A2ull, 0x127FFFB9FFDFB5F6ull,
0x411FFFDDFFDBF4D6ull, 0x0801000804000603ull, 0x0003FFEF27EEBE74ull, 0x7645FFFECBFEA79Eull,
};
constexpr array<uint64, N_SQUARES> BishopMagics = {
0xFFEDF9FD7CFCFFFFull, 0xFC0962854A77F576ull, 0x5822022042000000ull, 0x2CA804A100200020ull,
0x0204042200000900ull, 0x2002121024000002ull, 0xFC0A66C64A7EF576ull, 0x7FFDFDFCBD79FFFFull,
0xFC0846A64A34FFF6ull, 0xFC087A874A3CF7F6ull, 0x1001080204002100ull, 0x1810080489021800ull,
0x0062040420010A00ull, 0x5028043004300020ull, 0xFC0864AE59B4FF76ull, 0x3C0860AF4B35FF76ull,
0x73C01AF56CF4CFFBull, 0x41A01CFAD64AAFFCull, 0x040C0422080A0598ull, 0x4228020082004050ull,
0x0200800400E00100ull, 0x020B001230021040ull, 0x7C0C028F5B34FF76ull, 0xFC0A028E5AB4DF76ull,
0x0020208050A42180ull, 0x001004804B280200ull, 0x2048020024040010ull, 0x0102C04004010200ull,
0x020408204C002010ull, 0x02411100020080C1ull, 0x102A008084042100ull, 0x0941030000A09846ull,
0x0244100800400200ull, 0x4000901010080696ull, 0x0000280404180020ull, 0x0800042008240100ull,
0x0220008400088020ull, 0x04020182000904C9ull, 0x0023010400020600ull, 0x0041040020110302ull,
0xDCEFD9B54BFCC09Full, 0xF95FFA765AFD602Bull, 0x1401210240484800ull, 0x0022244208010080ull,
0x1105040104000210ull, 0x2040088800C40081ull, 0x43FF9A5CF4CA0C01ull, 0x4BFFCD8E7C587601ull,
0xFC0FF2865334F576ull, 0xFC0BF6CE5924F576ull, 0x80000B0401040402ull, 0x0020004821880A00ull,
0x8200002022440100ull, 0x0009431801010068ull, 0xC3FFB7DC36CA8C89ull, 0xC3FF8A54F4CA2C89ull,
0xFFFFFCFCFD79EDFFull, 0xFC0863FCCB147576ull, 0x040C000022013020ull, 0x2000104000420600ull,
0x0400000260142410ull, 0x0800633408100500ull, 0xFC087E8E4BB2F736ull, 0x43FF9E4EF4CA2C89ull,
};
// Pyrrhic -- must see kingAttacks etc
namespace
{
extern int TB_LARGEST; // Set by Pyrrhic in tb_init()
#include "pyrrhic/tbprobe.cpp"
using namespace std; // only after pyrrhic
} // leave local
/// masks.c
array<array<int, N_SQUARES>, N_SQUARES> DistanceBetween;
array<array<int, 1 << N_FILES>, N_FILES> KingPawnFileDistance;
array<array<uint64, N_SQUARES>, N_COLORS> KingAreaMasks, ForwardFileMasks, PassedPawnMasks, PawnConnectedMasks, OutpostSquareMasks;
array<uint64, N_FILES> AdjacentFilesMasks;
array<uint64, N_COLORS> OutpostRanksMasks;
int distanceBetween(int s1, int s2) {
assert(0 <= s1 && s1 < N_SQUARES);
assert(0 <= s2 && s2 < N_SQUARES);
return DistanceBetween[s1][s2];
}
int kingPawnFileDistance(uint64 pawns, int ksq) {
pawns |= pawns >> 8; pawns |= pawns >> 16; pawns |= pawns >> 32;
assert(0 <= FileOf(ksq) && FileOf(ksq) < N_FILES);
assert((pawns & 0xFF) < (1ull << N_FILES));
return KingPawnFileDistance[FileOf(ksq)][pawns & 0xFF];
}
int openFileCount(uint64 pawns) {
pawns |= pawns >> 8; pawns |= pawns >> 16; pawns |= pawns >> 32;
return popcount(~pawns & 0xFF);
}
uint64 kingAreaMasks(int colour, int sq) {
assert(0 <= colour && colour < N_COLORS);
assert(0 <= sq && sq < N_SQUARES);
return KingAreaMasks[colour][sq];
}
uint64 forwardRanksMasks(int colour, int rank) {
assert(0 <= colour && colour < N_COLORS);
assert(0 <= rank && rank < N_RANKS);
return Forward[colour][rank] | Line[rank];
}
uint64 forwardFileMasks(int colour, int sq) {
assert(0 <= colour && colour < N_COLORS);
assert(0 <= sq && sq < N_SQUARES);
return ForwardFileMasks[colour][sq];
}
uint64 adjacentFilesMasks(int file) {
assert(0 <= file && file < N_FILES);
return AdjacentFilesMasks[file];
}
uint64 passedPawnMasks(int colour, int sq) {
assert(0 <= colour && colour < N_COLORS);
assert(0 <= sq && sq < N_SQUARES);
return PassedPawnMasks[colour][sq];
}
uint64 pawnConnectedMasks(int colour, int sq) {
assert(0 <= colour && colour < N_COLORS);
assert(0 <= sq && sq < N_SQUARES);
return PawnConnectedMasks[colour][sq];
}
uint64 outpostSquareMasks(int colour, int sq) {
assert(0 <= colour && colour < N_COLORS);
assert(0 <= sq && sq < N_SQUARES);
return OutpostSquareMasks[colour][sq];
}
uint64 outpostRanksMasks(int colour) {
assert(0 <= colour && colour < N_COLORS);
return OutpostRanksMasks[colour];
}
void initMasks()
{
// Init a table for the distance between two given squares
for (int sq1 = 0; sq1 < N_SQUARES; sq1++)
for (int sq2 = 0; sq2 < N_SQUARES; sq2++)
DistanceBetween[sq1][sq2] = Max(abs(FileOf(sq1) - FileOf(sq2)), abs(rankOf(sq1) - rankOf(sq2)));
// Init a table to compute the distance between Pawns and Kings file-wise
for (uint64 mask = 0ull; mask <= 0xFF; mask++)
{
for (int file = 0; file < N_FILES; file++)
{
// Look at only one side at a time by shifting off the other pawns
uint64 left = (0xFFull & (mask << (N_FILES - file - 1))) >> (N_FILES - file - 1);
uint64 right = (mask >> file) << file;
// Find closest Pawn on each side. If no pawn, use "max" distance
int ldist = left ? file - msb(left) : N_FILES - 1;
int rdist = right ? lsb(right) - file : N_FILES - 1;
// Take the min distance, unless there are no pawns, then use 0
int dist = (left | right) ? Min(ldist, rdist) : 0;
KingPawnFileDistance[file][mask] = dist;
}
}
// Init a table for the King Areas. Use the King's square, the King's target
// squares, and the squares within the pawn shield. When on the A/H files, extend
// the King Area to include an additional file, namely the C and F file respectively
for (int sq = 0; sq < N_SQUARES; sq++)
{
KingAreaMasks[WHITE][sq] = kingAttacks(sq) | Bit(sq) | (kingAttacks(sq) << 8);
KingAreaMasks[BLACK][sq] = kingAttacks(sq) | Bit(sq) | (kingAttacks(sq) >> 8);
KingAreaMasks[WHITE][sq] |= FileOf(sq) != 0 ? 0ull : KingAreaMasks[WHITE][sq] << 1;
KingAreaMasks[BLACK][sq] |= FileOf(sq) != 0 ? 0ull : KingAreaMasks[BLACK][sq] << 1;
KingAreaMasks[WHITE][sq] |= FileOf(sq) != 7 ? 0ull : KingAreaMasks[WHITE][sq] >> 1;
KingAreaMasks[BLACK][sq] |= FileOf(sq) != 7 ? 0ull : KingAreaMasks[BLACK][sq] >> 1;
}
// Init a table of bitmasks for the ranks at or above a given rank, by colour
// Init a table of bitmasks for the squares on a file above a given square, by colour
for (int sq = 0; sq < N_SQUARES; sq++) {
ForwardFileMasks[WHITE][sq] = File[FileOf(sq)] & Forward[WHITE][rankOf(sq)];
ForwardFileMasks[BLACK][sq] = File[FileOf(sq)] & Forward[BLACK][rankOf(sq)];
}
// Init a table of bitmasks containing the files next to a given file
for (int file = 0; file < N_FILES; file++)
{
AdjacentFilesMasks[file] = File[Max(0, file - 1)];
AdjacentFilesMasks[file] |= File[Min(N_FILES - 1, file + 1)];
AdjacentFilesMasks[file] &= ~File[file];
}
// Init a table of bitmasks to check if a given pawn has any opposition
for (int colour = WHITE; colour <= BLACK; colour++)
for (int sq = 0; sq < N_SQUARES; sq++)
PassedPawnMasks[colour][sq] = ~forwardRanksMasks(!colour, rankOf(sq))
& (adjacentFilesMasks(FileOf(sq)) | File[FileOf(sq)]);
// Init a table of bitmasks to check if a square is an outpost relative
// to opposing pawns, such that no enemy pawn may attack the square with ease
for (int colour = WHITE; colour <= BLACK; colour++)
for (int sq = 0; sq < N_SQUARES; sq++)
OutpostSquareMasks[colour][sq] = PassedPawnMasks[colour][sq] & ~File[FileOf(sq)];
// Init a pair of bitmasks to check if a square may be an outpost, by colour
OutpostRanksMasks[WHITE] = Line[3] | Line[4] | Line[5];
OutpostRanksMasks[BLACK] = Line[2] | Line[3] | Line[4];
// Init a table of bitmasks to check for supports for a given pawn
for (int sq = 8; sq < 56; sq++) {
PawnConnectedMasks[WHITE][sq] = pawnAttacks(BLACK, sq) | pawnAttacks(BLACK, sq + 8);
PawnConnectedMasks[BLACK][sq] = pawnAttacks(WHITE, sq) | pawnAttacks(WHITE, sq - 8);
}
}
/// network.h
#define PKNETWORK_INPUTS (224)
#define PKNETWORK_LAYER1 ( 32)
#define PKNETWORK_OUTPUTS ( 2)
typedef struct PKNetwork {
// PKNetworks are of the form [Input, Hidden Layer 1, Output Layer]
// Our current Network is [224x32, 32x1]. The Network is trained to
// output a Score in CentiPawns for the Midgame and Endgame
// We transpose the Input Weights matrix in order to get better
// caching and memory lookups, since when computing we iterate
// over only the ~20 Inputs set out of the 224 possible Inputs
ALIGN64 float inputWeights[PKNETWORK_INPUTS][PKNETWORK_LAYER1];
ALIGN64 float inputBiases[PKNETWORK_LAYER1];
ALIGN64 float layer1Weights[PKNETWORK_OUTPUTS][PKNETWORK_LAYER1];
ALIGN64 float layer1Biases[PKNETWORK_OUTPUTS];
} PKNetwork;
/// network.c
PKNetwork PKNN;
static array<string, 224> PKWeights = {
#include "weights/pknet_224x32x2.net"
""
};
inline int computePKNetworkIndex(int colour, int piece, int sq)
{
return (64 + 48) * colour + (48 * (piece == KING)) + sq - 8 * (piece == PAWN);
}
packed_t computePKNetwork(const Board_& board)
{
uint64 pawns = board.Pawns();
uint64 kings = board.Kings();
uint64 black = board.colors_[BLACK];
float layer1Neurons[PKNETWORK_LAYER1];
float outputNeurons[PKNETWORK_OUTPUTS];
// Layer 1: Compute the values in the hidden Neurons of Layer 1
// by looping over the Kings and Pawns bitboards, and applying
// the weight which corresponds to each piece. We break the Kings
// into two nearly duplicate steps, in order to more efficiently
// set and update the Layer 1 Neurons initially
{ // Do one King first so we can set the Neurons
int sq = poplsb(&kings);
int idx = computePKNetworkIndex(HasBit(black, sq), KING, sq);
for (int i = 0; i < PKNETWORK_LAYER1; i++)
layer1Neurons[i] = PKNN.inputBiases[i] + PKNN.inputWeights[idx][i];
}
{ // Do the remaining King as we would do normally
int sq = poplsb(&kings);
int idx = computePKNetworkIndex(HasBit(black, sq), KING, sq);
for (int i = 0; i < PKNETWORK_LAYER1; i++)
layer1Neurons[i] += PKNN.inputWeights[idx][i];
}
while (pawns) {
int sq = poplsb(&pawns);
int idx = computePKNetworkIndex(HasBit(black, sq), PAWN, sq);
for (int i = 0; i < PKNETWORK_LAYER1; i++)
layer1Neurons[i] += PKNN.inputWeights[idx][i];
}
// Layer 2: Trivially compute the Output layer. Apply a ReLU here.
// We do not apply a ReLU in Layer 1, since we already know that all
// of the Inputs in Layer 1 are going to be zeros or ones
for (int i = 0; i < PKNETWORK_OUTPUTS; i++) {
outputNeurons[i] = PKNN.layer1Biases[i];
for (int j = 0; j < PKNETWORK_LAYER1; j++)
if (layer1Neurons[j] >= 0.0)
outputNeurons[i] += layer1Neurons[j] * PKNN.layer1Weights[i][j];
}
assert(PKNETWORK_OUTPUTS == N_PHASES);
return MakeScore((int)outputNeurons[MG], (int)outputNeurons[EG]);
}
void initPKNetwork()
{
for (int i = 0; i < PKNETWORK_LAYER1; i++)
{
string temp = PKWeights[i];
temp.push_back(0);
auto weights = &temp[0];
strtok(weights, " ");
for (int j = 0; j < PKNETWORK_INPUTS; j++)
PKNN.inputWeights[j][i] = static_cast<float>(atof(strtok(NULL, " ")));
PKNN.inputBiases[i] = static_cast<float>(atof(strtok(NULL, " ")));
}
for (int i = 0; i < PKNETWORK_OUTPUTS; i++)
{
string temp = PKWeights[i + PKNETWORK_LAYER1];
temp.push_back(0);
auto weights = &temp[0];
strtok(weights, " ");
for (int j = 0; j < PKNETWORK_LAYER1; j++)
PKNN.layer1Weights[i][j] = static_cast<float>(atof(strtok(NULL, " ")));
PKNN.layer1Biases[i] = static_cast<float>(atof(strtok(NULL, " ")));
}
}
/// nnue/types.h
#if defined(USE_AVX2)
#include "archs/avx2.h"
#elif defined(USE_AVX)
#include "archs/avx.h"
#elif defined(USE_SSSE3)
#include "archs/ssse3.h"
#endif
constexpr int INSIZE = 20480, KPSIZE = 768, L1SIZE = 1536, L2SIZE = 8, L3SIZE = 32, OUTSIZE = 1;
constexpr int NUM_REGS = 16;
typedef struct NNUEDelta {
int piece, from, to;
} NNUEDelta;
typedef struct NNUEAccumulator {
int changes, accurate[N_COLORS];
NNUEDelta deltas[3];
ALIGN64 int16_t values[N_COLORS][KPSIZE];
} NNUEAccumulator;
typedef struct NNUEAccumulatorTableEntry {
NNUEAccumulator accumulator;
uint64 occupancy[N_COLORS][N_COLORS][N_PIECES - 1];
} NNUEAccumulatorTableEntry;
typedef struct NNUEEvaluator {
NNUEAccumulator stack[MAX_PLY + 4]; // Each ply of search
NNUEAccumulator* current; // Pointer of the current stack location