/
fruit21chess.lua
15536 lines (10809 loc) · 350 KB
/
fruit21chess.lua
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
--
-- Fruit 2.1 chess engine by Fabien Letouzey, 2004-2005.
-- At http://www.fruitchess.com, http://wbec-ridderkerk.nl/
--
-- Port to Lua language by http://chessforeva.blogspot.com, 2011
--
-- Lua is a scripting language, this means: not a strong chess
-- But this is a smart AI anyway.
--
-- There is no opening book. lua library for chess openings is available at
-- Chessforeva's site. Or develop it.
--
-- Samples and all the usage is obvious down at the end.
-- Free usage and much thanks to Fabien!
--
require "bit";
-- colour.h
-- constants
UseMcache = true; -- to use files for faster performance (saves some memory variables),
-- set "false" for normal lua, needed for very slow lua case
TRUE = 1;
FALSE = 0;
UseTable = true; -- const bool
MaterialTableSize = 64 * 1024; -- const size of Material hashing (array elements to use)
PawnTableSize = 64 * 1024; -- const size of Pawn hashing (array elements to use)
UseTrans = true; -- const bool
TransSize = 64 * 1024; -- const size of transp-table (array elements to use)
-- it is not a memory hash size, because there is no memory allocation at all
bestmv = ""; -- string contains best move
bestmv2 = ""; -- string contains pgn-format of the move
ShowInfo = false; -- set true to show thinking!
iDbg01 = false; -- internal for debugging
ColourNone = -1; -- const int
White = 0; -- const int
Black = 1; -- const int
ColourNb = 2; -- const int
WhiteFlag = bit.lshift(1,White); -- const int
BlackFlag = bit.lshift(1,Black); -- const int
WxorB = bit.bxor(White,Black);
bnot1 = bit.bnot(1);
bnot3 = bit.bnot(3);
bnotF = bit.bnot(0xF);
V07777 = 4095; -- const int
bnotV07777 = bit.bnot( V07777 ); -- const int
bnotV77 = bit.bnot(0x77); -- const int
-- should be true, or error otherwise
function ASSERT(id,logic)
if( not logic ) then
print("ASSERT FAIL on id=" .. string.format("%d",id));
end
end
-- (if ? then : else) substitute
function iif(ask, ontrue, onfalse)
if( ask ) then
return ontrue;
end
return onfalse;
end
-- convert bytes (little endian) to a 32-bit two's complement integer (not used)
function bytes_to_int(b1, b2, b3, b4)
if(b3==nil) then
b3 = 0;
end
if(b4==nil) then
b4 = 0;
end
local n = b1 + (b2*256) + (b3*65536) + (b4*16777216);
if(n > 2147483647) then
return (n - 4294967296);
end
return n;
end
-- constructor to provide string as a parm
function string_t()
local b = {};
b.v = "";
return b;
end
-- constructor to provide int as a parm
function int_t ()
local b = {};
b.v = 0;
return b;
end
-- my_fatal()
function my_fatal( errmess ) -- for error case
print( "my-error: "..errmess );
end
function COLOUR_IS_OK(colour)
return (bit.band(colour,bnot1)==0);
end
function COLOUR_IS_WHITE(colour)
return (colour==White);
end
function COLOUR_IS_BLACK(colour)
return (colour~=White);
end
function COLOUR_FLAG(colour)
return (colour+1);
end
function COLOUR_IS(piece,colour)
return (FLAG_IS(piece,colour+1));
end
function FLAG_IS(piece,flag)
return (bit.band(piece,flag)~=0);
end
function COLOUR_OPP(colour)
return bit.bxor(colour,WxorB);
end
-- end of colour.h
-- piece.h
-- constants
WhitePawnFlag = bit.lshift(1,2); -- const int
BlackPawnFlag = bit.lshift(1,3); -- const int
KnightFlag = bit.lshift(1,4); -- const int
BishopFlag = bit.lshift(1,5); -- const int
RookFlag = bit.lshift(1,6); -- const int
KingFlag = bit.lshift(1,7); -- const int
PawnFlags = bit.bor(WhitePawnFlag, BlackPawnFlag); -- const int
QueenFlags = bit.bor(BishopFlag, RookFlag); -- const int
PieceNone64 = 0; -- const int
WhitePawn64 = WhitePawnFlag; -- const int
BlackPawn64 = BlackPawnFlag; -- const int
Knight64 = KnightFlag; -- const int
Bishop64 = BishopFlag; -- const int
Rook64 = RookFlag; -- const int
Queen64 = QueenFlags; -- const int
King64 = KingFlag; -- const int
PieceNone256 = 0; -- const int
WhitePawn256 = bit.bor(WhitePawn64,WhiteFlag); -- const int
BlackPawn256 = bit.bor(BlackPawn64,BlackFlag); -- const int
WhiteKnight256 = bit.bor(Knight64,WhiteFlag); -- const int
BlackKnight256 = bit.bor(Knight64,BlackFlag); -- const int
WhiteBishop256 = bit.bor(Bishop64,WhiteFlag); -- const int
BlackBishop256 = bit.bor(Bishop64,BlackFlag); -- const int
WhiteRook256 = bit.bor(Rook64,WhiteFlag); -- const int
BlackRook256 = bit.bor(Rook64,BlackFlag); -- const int
WhiteQueen256 = bit.bor(Queen64,WhiteFlag); -- const int
BlackQueen256 = bit.bor(Queen64,BlackFlag); -- const int
WhiteKing256 = bit.bor(King64,WhiteFlag); -- const int
BlackKing256 = bit.bor(King64,BlackFlag); -- const int
PieceNb = 256; -- const int
WhitePawn12 = 0; -- const int
BlackPawn12 = 1; -- const int
WhiteKnight12 = 2; -- const int
BlackKnight12 = 3; -- const int
WhiteBishop12 = 4; -- const int
BlackBishop12 = 5; -- const int
WhiteRook12 = 6; -- const int
BlackRook12 = 7; -- const int
WhiteQueen12 = 8; -- const int
BlackQueen12 = 9; -- const int
WhiteKing12 = 10; -- const int
BlackKing12 = 11; -- const int
-- "constants"
PawnMake = { WhitePawn256, BlackPawn256 }; -- const int[ColourNb]
PieceFrom12 = { WhitePawn256, BlackPawn256, WhiteKnight256, BlackKnight256,
WhiteBishop256, BlackBishop256, WhiteRook256, BlackRook256,
WhiteQueen256, BlackQueen256, WhiteKing256, BlackKing256 }; -- const int[12]
PieceString = "PpNnBbRrQqKk"; -- const char[12+1]
PawnMoveInc = { 16, -16 }; -- const int[ColourNb]
KnightInc = { -33, -31, -18, -14, 14, 18, 31, 33, 0 }; -- const int[8+1]
BishopInc = { -17, -15, 15, 17, 0 }; -- const int[4+1]
RookInc = { -16, -1, 1, 16, 0 }; -- const int[4+1]
QueenInc = { -17, -16, -15, -1, 1, 15, 16, 17, 0 }; -- const[8+1]
KingInc = { -17, -16, -15, -1, 1, 15, 16, 17, 0 }; -- const[8+1]
-- variables
PieceTo12 = {}; -- int[PieceNb]
PieceOrder = {}; -- int[PieceNb]
PieceInc = {}; -- const
-- macros
function PAWN_OPP(pawn)
return bit.bxor(pawn,bit.bxor(WhitePawn256,BlackPawn256));
end
function PIECE_COLOUR(piece)
return (bit.band(piece,3)-1);
end
function PIECE_TYPE(piece)
return bit.band(piece,bnot3);
end
function PIECE_IS_PAWN(piece)
return (bit.band(piece,PawnFlags)~=0);
end
function PIECE_IS_KNIGHT(piece)
return (bit.band(piece,KnightFlag)~=0);
end
function PIECE_IS_BISHOP(piece)
return (bit.band(piece,QueenFlags)==BishopFlag);
end
function PIECE_IS_ROOK(piece)
return (bit.band(piece,QueenFlags)==RookFlag);
end
function PIECE_IS_QUEEN(piece)
return (bit.band(piece,QueenFlags)==QueenFlags);
end
function PIECE_IS_KING(piece)
return (bit.band(piece,KingFlag)~=0);
end
function PIECE_IS_SLIDER(piece)
return (bit.band(piece,QueenFlags)~=0);
end
-- end of piece.h
-- square.h
-- constants
FileNb = 16; -- const int
RankNb = 16; -- const int
SquareNb = FileNb*RankNb; -- const int
FileInc = 1; -- const int
RankInc = 16; -- const int
FileNone = 0; -- const int
FileA = 0x4; -- const int
FileB = 0x5; -- const int
FileC = 0x6; -- const int
FileD = 0x7; -- const int
FileE = 0x8; -- const int
FileF = 0x9; -- const int
FileG = 0xA; -- const int
FileH = 0xB; -- const int
RankNone = 0; -- const int
Rank1 = 0x4; -- const int
Rank2 = 0x5; -- const int
Rank3 = 0x6; -- const int
Rank4 = 0x7; -- const int
Rank5 = 0x8; -- const int
Rank6 = 0x9; -- const int
Rank7 = 0xA; -- const int
Rank8 = 0xB; -- const int
SquareNone = 0; -- const int
A1=0x44; B1=0x45; C1=0x46; D1=0x47; E1=0x48; F1=0x49; G1=0x4A; H1=0x4B; -- const int
A2=0x54; B2=0x55; C2=0x56; D2=0x57; E2=0x58; F2=0x59; G2=0x5A; H2=0x5B; -- const int
A3=0x64; B3=0x65; C3=0x66; D3=0x67; E3=0x68; F3=0x69; G3=0x6A; H3=0x6B; -- const int
A4=0x74; B4=0x75; C4=0x76; D4=0x77; E4=0x78; F4=0x79; G4=0x7A; H4=0x7B; -- const int
A5=0x84; B5=0x85; C5=0x86; D5=0x87; E5=0x88; F5=0x89; G5=0x8A; H5=0x8B; -- const int
A6=0x94; B6=0x95; C6=0x96; D6=0x97; E6=0x98; F6=0x99; G6=0x9A; H6=0x9B; -- const int
A7=0xA4; B7=0xA5; C7=0xA6; D7=0xA7; E7=0xA8; F7=0xA9; G7=0xAA; H7=0xAB; -- const int
A8=0xB4; B8=0xB5; C8=0xB6; D8=0xB7; E8=0xB8; F8=0xB9; G8=0xBA; H8=0xBB; -- const int
Dark = 0; -- const int
Light = 1; -- const int
-- variables
SquareTo64 = {}; -- int[SquareNb]
SquareIsPromote = {}; -- bool[SquareNb]
-- "constants"
SquareFrom64 = {
A1, B1, C1, D1, E1, F1, G1, H1,
A2, B2, C2, D2, E2, F2, G2, H2,
A3, B3, C3, D3, E3, F3, G3, H3,
A4, B4, C4, D4, E4, F4, G4, H4,
A5, B5, C5, D5, E5, F5, G5, H5,
A6, B6, C6, D6, E6, F6, G6, H6,
A7, B7, C7, D7, E7, F7, G7, H7,
A8, B8, C8, D8, E8, F8, G8, H8,
}; -- const int[64]
RankMask = { 0, 0xF }; -- const int[ColourNb]
PromoteRank = { 0xB0, 0x40 }; -- const int[ColourNb]
-- macros
function SQUARE_IS_OK(square)
return (bit.band(square-0x44,bnotV77)==0);
end
function SQUARE_MAKE(file,rank)
return bit.bor(bit.lshift(rank,4),file);
end
function SQUARE_FILE(square)
return bit.band(square,0xF);
end
function SQUARE_RANK(square)
return bit.rshift(square,4);
end
function SQUARE_EP_DUAL(square)
return bit.bxor(square,16);
end
function SQUARE_COLOUR(square)
return bit.band( bit.bxor(square,bit.rshift(square,4)),1);
end
function SQUARE_FILE_MIRROR(square)
return bit.bxor(square,0x0F);
end
function SQUARE_RANK_MIRROR(square)
return bit.bxor(square,0xF0);
end
function FILE_OPP(file)
return bit.bxor(file,0xF);
end
function RANK_OPP(rank)
return bit.bxor(rank,0xF);
end
function PAWN_RANK(square,colour)
return bit.bxor(SQUARE_RANK(square),RankMask[1+colour]);
end
function PAWN_PROMOTE(square,colour)
return bit.bor(PromoteRank[1+colour],bit.band(square,0xF));
end
-- end of square.h
-- board.h
-- constants
Empty = 0; -- const int
Edge = Knight64; -- const int HACK: uncoloured knight
WP = WhitePawn256; -- const int
WN = WhiteKnight256; -- const int
WB = WhiteBishop256; -- const int
WR = WhiteRook256; -- const int
WQ = WhiteQueen256; -- const int
WK = WhiteKing256; -- const int
BP = BlackPawn256; -- const int
BN = BlackKnight256; -- const int
BB = BlackBishop256; -- const int
BR = BlackRook256; -- const int
BQ = BlackQueen256; -- const int
BK = BlackKing256; -- const int
FlagsNone = 0; -- const int
FlagsWhiteKingCastle = bit.lshift(1,0) ; -- const int
FlagsWhiteQueenCastle = bit.lshift(1,1) ; -- const int
FlagsBlackKingCastle = bit.lshift(1,2) ; -- const int
FlagsBlackQueenCastle = bit.lshift(1,3) ; -- const int
StackSize = 4096; -- const int
-- macros
function KING_POS(board,colour)
return board.piece[1+colour][1+0];
end
-- types
function board_t ()
local b = {};
b.square = { 0, 0 }; -- int[SquareNb]
b.pos = { 0, 0 }; -- int[SquareNb]
b.piece = {}; -- int[ColourNb][32] only 17 are needed
b.piece[1+0] = {0};
b.piece[1+1] = {0};
b.piece_size = { 0, 0 }; -- int[ColourNb]
b.pawn = {}; -- int[ColourNb][16] only 9 are needed
b.pawn[1+0] = {0};
b.pawn[1+1] = {0};
b.pawn_size = { 0, 0 }; -- int[ColourNb]
b.piece_nb = 0; -- int
b.number = {}; -- int[16] only 12 are needed
b.pawn_file = {}; -- int[ColourNb][FileNb];
b.pawn_file[1+0] = {0};
b.pawn_file[1+1] = {0};
b.turn = 0; -- int
b.flags = 0; -- int
b.ep_square = 0; -- int
b.ply_nb = 0; -- int
b.sp = 0; -- int TODO: MOVE ME?
b.cap_sq = 0; -- int
b.opening = 0; -- int
b.endgame = 0; -- int
b.key = 0; -- uint64
b.pawn_key = 0; -- uint64
b.material_key = 0; -- uint64
b.stack = {0}; -- uint64[StackSize];
b.movenumb = 0; -- int
return b;
end
-- end of board.h
-- move.h
-- constants
MoveNone = 0; -- const int HACK: a1a1 cannot be a legal move
Movenil = 11; -- const int HACK: a1d2 cannot be a legal move
MoveNormal = bit.lshift(0,14); -- const int
MoveCastle = bit.lshift(1,14); -- const int
MovePromote = bit.lshift(2,14); -- const int
MoveEnPassant = bit.lshift(3,14); -- const int
MoveFlags = bit.lshift(3,14); -- const int
MovePromoteKnight = bit.bor(MovePromote,bit.lshift(0,12)); -- const int
MovePromoteBishop = bit.bor(MovePromote,bit.lshift(1,12)); -- const int
MovePromoteRook = bit.bor(MovePromote,bit.lshift(2,12)); -- const int
MovePromoteQueen = bit.bor(MovePromote,bit.lshift(3,12)); -- const int
MoveAllFlags = bit.lshift(0xF,12); -- const int
nilMoveString = "nil"; -- const char[] "0000" in UCI
PromotePiece = { Knight64, Bishop64, Rook64, Queen64 }; -- int[4]
-- macros
function MOVE_MAKE(from,to)
return bit.bor( bit.lshift(SquareTo64[1+from],6) , SquareTo64[1+to]);
end
function MOVE_MAKE_FLAGS(from,to,flags) return bit.bor( bit.lshift(SquareTo64[1+from],6), bit.bor(SquareTo64[1+to],flags));
end
function MOVE_FROM(move)
return SquareFrom64[1+ bit.band(bit.rshift(move,6), 63)];
end
function MOVE_TO(move)
return SquareFrom64[1+ bit.band(move, 63)];
end
function MOVE_IS_SPECIAL(move)
return ( bit.band(move,MoveFlags)~=MoveNormal );
end
function MOVE_IS_PROMOTE(move)
return ( bit.band(move,MoveFlags)==MovePromote );
end
function MOVE_IS_EN_PASSANT(move)
return ( bit.band(move,MoveFlags)==MoveEnPassant );
end
function MOVE_IS_CASTLE(move)
return ( bit.band(move,MoveFlags)==MoveCastle );
end
function MOVE_PIECE(move,board)
return ((board).square[1+MOVE_FROM(move)]);
end
-- end of move.h
-- attack.h
-- types
function attack_t ()
local b = {};
b.dn = 0; -- int
b.ds = {}; -- int[2+1]
b.di = {}; -- int[2+1]
return b;
end
-- variables
DeltaIncLine = {}; -- int[DeltaNb]
DeltaIncAll = {}; -- int[DeltaNb]
DeltaMask = {}; -- int[DeltaNb]
IncMask = {}; -- int[IncNb]
PieceCode = {}; -- int[PieceNb]
PieceDeltaSize = {}; -- int[4][256] 4kB
PieceDeltaDelta = {}; -- int[4][256][4] 16kB
-- macros
function IS_IN_CHECK(board,colour)
return is_attacked(board,KING_POS(board,colour),COLOUR_OPP(colour));
end
function DELTA_INC_LINE(delta)
return DeltaIncLine[1+DeltaOffset+delta];
end
function DELTA_INC_ALL(delta)
return DeltaIncAll[1+DeltaOffset+delta];
end
function DELTA_MASK(delta)
return DeltaMask[1+DeltaOffset+delta];
end
function INC_MASK(inc)
return IncMask[1+IncOffset+inc];
end
function PSEUDO_ATTACK(piece,delta)
return (bit.band(piece,DELTA_MASK(delta))~=0);
end
function PIECE_ATTACK(board,piece,from,to)
return PSEUDO_ATTACK(piece,to-from) and line_is_empty(board,from,to);
end
function SLIDER_ATTACK(piece,inc)
return (bit.band(piece,INC_MASK(inc))~=0);
end
function ATTACK_IN_CHECK(attack)
return (attack.dn~=0);
end
-- end of attack.h
-- trans.h
-- constants
UseModulo = false; -- const bool
DateSize = 16; -- const int
DepthNone = -128; -- const int
ClusterSize = 4; -- const int, not a hash size
-- types
function entry_t()
local b = {};
b.lock = 0; -- uint32
b.move = 0; -- uint16
b.depth = 0; -- sint8
b.date = 0; -- uint8
b.move_depth = 0; -- sint8
b.flags = 0; -- uint8
b.min_depth = 0; -- sint8
b.max_depth = 0; -- sint8
b.min_value = 0; -- sint16
b.max_value = 0; -- sint16
return b;
end
function trans_t ()
local b = {};
b.table = {}; -- entry_t*
b.size = 0; -- uint32
b.mask = 0; -- uint32
b.date = 0; -- int
b.age = {}; -- int[DateSize]
b.used = 0; -- uint32
b.read_nb = 0; -- sint64
b.read_hit = 0; -- sint64
b.write_nb = 0; -- sint64
b.write_hit = 0; -- sint64
b.write_collision = 0; -- sint64
return b;
end
function trans_rtrv()
local b = {};
b.trans_move = 0; -- int
b.trans_min_depth = 0; -- int
b.trans_max_depth = 0; -- int
b.trans_min_value = 0; -- int
b.trans_max_value = 0; -- int
return b;
end
-- variables
Trans = trans_t (); -- trans_t [1]
TransRv = trans_rtrv(); -- retriever
-- end of trans.h
-- hash.h
-- macros
function uint32(i)
return bit.band(i, 0xFFFFFFFF);
end
function KEY_INDEX(key)
return uint32(key);
end
function KEY_LOCK(key) -- no 64 bits, so, we use the original key
return key; -- uint32(bit.rshift(key,32));
end
-- constants
RandomPiece = 0; -- 12 * 64 const int
RandomCastle = 768; -- 4 const int
RandomEnPassant = 772; -- 8 const int
RandomTurn = 780; -- 1 const int
-- end of hash.h
-- list.h
-- constants
ListSize = 256; -- const int
UseStrict = true; -- const bool
-- types
function list_t ()
local b = {};
b.size = 0; -- int
b.move = {}; -- int[ListSize]
b.value = {}; -- short int[ListSize]
return b;
end
function alist_t ()
local b = {};
b.size = 0; -- int
b.square = {}; -- int[15]
return b;
end
function alists_t ()
local b = {};
b.alist = {}; --alist_t [ColourNb][1]
b.alist[1+0] = alist_t ();
b.alist[1+1] = alist_t ();
return b;
end
-- macros
function LIST_ADD(list,mv)
list.move[1+list.size]=mv;
list.size = list.size + 1;
end
function LIST_CLEAR(list)
list.move = {};
list.size = 0;
end
-- end of list.h
-- material.h
-- constants
MAT_NONE = 0; MAT_KK = 1; MAT_KBK = 2; MAT_KKB = 3; MAT_KNK = 4; MAT_KKN = 5;
MAT_KPK = 6; MAT_KKP = 7; MAT_KQKQ = 8; MAT_KQKP = 9; MAT_KPKQ = 10;
MAT_KRKR = 11; MAT_KRKP = 12; MAT_KPKR = 13; MAT_KBKB = 14; MAT_KBKP = 15;
MAT_KPKB = 16; MAT_KBPK = 17; MAT_KKBP = 18; MAT_KNKN = 19; MAT_KNKP = 20;
MAT_KPKN = 21; MAT_KNPK = 22; MAT_KKNP = 23; MAT_KRPKR = 24; MAT_KRKRP = 25;
MAT_KBPKB = 26; MAT_KBKBP = 27; MAT_NB = 28;
DrawNodeFlag = bit.lshift(1,0); -- const int
DrawBishopFlag = bit.lshift(1,1); -- const int
MatRookPawnFlag = bit.lshift(1,0); -- const int
MatBishopFlag = bit.lshift(1,1); -- const int
MatKnightFlag = bit.lshift(1,2); -- const int
MatKingFlag = bit.lshift(1,3); -- const int
-- constants
PawnPhase = 0; -- const int
KnightPhase = 1; -- const int
BishopPhase = 1; -- const int
RookPhase = 2; -- const int
QueenPhase = 4; -- const int
TotalPhase = (PawnPhase * 16) + (KnightPhase * 4) +
(BishopPhase * 4) + RookPhase * 4 + (QueenPhase * 2); -- const int
-- constants and variables
MaterialWeight = 256; -- 100% const int
PawnOpening = 80; -- was 100 const int
PawnEndgame = 90; -- was 100 const int
KnightOpening = 325; -- const int
KnightEndgame = 325; -- const int
BishopOpening = 325; -- const int
BishopEndgame = 325; -- const int
RookOpening = 500; -- const int
RookEndgame = 500; -- const int
QueenOpening = 1000; -- const int
QueenEndgame = 1000; -- const int
BishopPairOpening = 50; -- const int
BishopPairEndgame = 50; -- const int
-- types
function material_info_t ()
local b = {};
b.lock = 0; -- uint32
b.recog = 0; -- uint8
b.flags = 0; -- uint8
b.cflags = { 0, 0 }; -- uint8[ColourNb]
b.mul = { 0, 0 }; -- uint8[ColourNb]
b.phase = 0; -- sint16
b.opening = 0; -- sint16
b.endgame = 0; -- sint16
return b;
end
function material_t ()
local b = {};
b.table = {}; -- entry_t*
b.size = 0; -- uint32
b.mask = 0; -- uint32
b.used = 0; -- uint32
b.read_nb = 0; -- sint64
b.read_hit = 0; -- sint64
b.write_nb = 0; -- sint64
b.write_collision = 0; -- sint64
return b;
end
-- variables
Material = material_t(); -- material_t[1]
-- material_info_copy ()
function material_info_copy ( dst, src )
dst.lock = src.lock;
dst.recog = src.recog;
dst.cflags[1+0] = src.cflags[1+0];
dst.cflags[1+1] = src.cflags[1+1];
dst.mul[1+0] = src.mul[1+0];
dst.mul[1+1] = src.mul[1+1];
dst.phase = src.phase;
dst.opening = src.opening;
dst.endgame = src.endgame;
dst.flags = src.flags;
end
-- end of material.h
-- move_do.h
-- types
function undo_t ()
local b = {};
b.capture = false; -- bool
b.capture_square = 0; -- int
b.capture_piece = 0; -- int
b.capture_pos = 0; -- int
b.pawn_pos = 0; -- int
b.turn = 0; -- int
b.flags = 0; -- int
b.ep_square = 0; -- int
b.ply_nb = 0; -- int
b.cap_sq = 0; -- int
b.opening = 0; -- int
b.endgame = 0; -- int
b.key = 0; -- uint64
b.pawn_key = 0; -- uint64
b.material_key = 0; -- uint64
return b;
end
-- variables
CastleMask = {}; -- int[SquareNb]
-- end of move_do.h
-- pawn.h
-- constants
BackRankFlag = bit.lshift(1,0); -- const int
-- types
function pawn_t ()
local b = {};
b.table = {}; -- entry_t*
b.size = 0; -- uint32
b.mask = 0; -- uint32
b.used = 0; -- uint32
b.read_nb = 0; -- sint64
b.read_hit = 0; -- sint64
b.write_nb = 0; -- sint64
b.write_collision = 0; -- sint64
return b;
end
function pawn_info_t ()
local b = {};
b.lock = 0; -- uint32
b.opening = 0; -- sint16
b.endgame = 0; -- sint16
b.flags = { 0, 0 }; -- uint8[ColourNb]
b.passed_bits = { 0, 0 }; -- uint8[ColourNb]
b.single_file = { 0, 0 }; -- uint8[ColourNb]
b.pad = 0; -- uint16
return b;
end
-- pawn_info_copy ()
function pawn_info_copy ( dst, src )
dst.lock = src.lock;
dst.opening = src.opening;
dst.endgame = src.endgame;
dst.flags[1+0] = src.flags[1+0];
dst.flags[1+1] = src.flags[1+1];
dst.passed_bits[1+0] = src.passed_bits[1+0];
dst.passed_bits[1+1] = src.passed_bits[1+1];
dst.single_file[1+0] = src.single_file[1+0];
dst.single_file[1+1] = src.single_file[1+1];
dst.pad = src.pad ;
end
-- constants and variables
Pawn = pawn_t(); -- pawn_t[1]
DoubledOpening = 10; -- const int
DoubledEndgame = 20; -- const int
IsolatedOpening = 10; -- const int
IsolatedOpeningOpen = 20; -- const int
IsolatedEndgame = 20; -- const int
BackwardOpening = 8; -- const int
BackwardOpeningOpen = 16; -- const int
BackwardEndgame = 10; -- const int
CandidateOpeningMin = 5; -- const int
CandidateOpeningMax = 55; -- const int
CandidateEndgameMin = 10; -- const int
CandidateEndgameMax = 110; -- const int
Bonus = {}; -- int[RankNb]
-- variables
BitEQ = {}; -- int[16]
BitLT = {}; -- int[16]
BitLE = {}; -- int[16]
BitGT = {}; -- int[16]
BitGE = {}; -- int[16]
BitFirst = {}; -- int[0x100]
BitLast = {}; -- int[0x100]
BitCount = {}; -- int[0x100]
BitRev = {}; -- int[0x100]
BitRank1 = {}; -- int[RankNb]
BitRank2 = {}; -- int[RankNb]
BitRank3 = {}; -- int[RankNb]
-- end of pawn.h
-- pst.h
-- constants
Opening = 0; -- const int