forked from tomitank/tomitankChess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtomitankChess.js
4450 lines (3427 loc) · 400 KB
/
tomitankChess.js
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
/*
tomitankChess 5.0 Copyright (C) 2017-2021 Tamas Kuzmics - tomitank
Mail: tanky.hu@gmail.com
Date: 2021.01.18.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
// Valtozok
var VERSION = '5.0';
var Nodes = 0; // Csomopont
var HashUsed = 0; // Hash szam
var BoardPly = 0; // Reteg szam
var MaxDepth = 64; // Max melyseg
var TimeStop = 0; // Ido vagas be
var HashDate = 0; // Hash ido tag
var BestMove = 0; // A legjobb lepes
var CurrDepth = 0; // Aktualis melyseg
var MoveCount = 0; // Osszes lepesszam
var StartTime = 0; // Kereses kezdo ido
var ScoreDrop = 0; // Csokkeno pontszam
var SideKeyLow = 0; // Oldal hashKey also
var SideKeyHigh = 0; // Oldal hashKey felso
var CastleRights = 0; // Sancolasok 4 biten!
var MinSearchTime = 0; // Min keresesi ido (ms)
var MaxSearchTime = 0; // Max keresesi ido (ms)
var CurrentPlayer = 0; // Aki lephet (Feher: 0)
var brd_fiftyMove = 0; // 50 lepes szamlalo..:)
var brd_hashKeyLow = 0; // Aktualis hashKey also bit
var brd_pawnKeyLow = 0; // Aktualis pawnKey also bit
var brd_hashKeyHigh = 0; // Aktualis hashKey felso bit
var brd_pawnKeyHigh = 0; // Aktualis pawnKey felso bit
var brd_PawnTable = null; // Atultetesi tabla uresen
var ShowEvalForUI = false; // Ertelekes megjelenites
var brd_Material = new Array(9); // Anyagi ertekek
var brd_pieceCount = new Array(15); // Babuk szama
var brd_pieceList = new Array(240); // Babuk helyzete
var brd_pieceIndex = new Array(64); // Babuk azonositoja
var SearchKillers = new Array(MaxDepth); // Gyilkos lepesek
var brd_moveList = new Array(MaxDepth * 256); // Lepes lista
var brd_moveScores = new Array(MaxDepth * 256); // Lepes ertek
var brd_moveStart = new Array(MaxDepth + 1); // Tomb hatarolo
var PieceKeysHigh = new Array(16 * 64); // Babu hashKey felso
var PieceKeysLow = new Array(16 * 64); // Babu hashKey also
var CastleKeysHigh = new Array(16); // Sancolas hashKey felso
var CastleKeysLow = new Array(16); // Sancolas hashKey also
var HistoryTable = new Array(15); // Elozmeny tabla
var DISTANCE = new Array(64); // SQ Kulonbseg
var MOVE_HISTORY = new Array(); // Lepeselozmeny
brd_moveStart[0] = 0; // Hack: Lepes lista index
// Allandok
var WHITE = 0x0;
var BLACK = 0x8;
var PAWN = 0x01;
var KNIGHT = 0x02;
var BISHOP = 0x03;
var ROOK = 0x04;
var QUEEN = 0x05;
var KING = 0x06;
var EMPTY = 0x40;
// Feher babuk 4 bit-en
var WHITE_PAWN = 0x01;
var WHITE_KNIGHT = 0x02;
var WHITE_BISHOP = 0x03;
var WHITE_ROOK = 0x04;
var WHITE_QUEEN = 0x05;
var WHITE_KING = 0x06;
// Fekete babuk 4 bit-en
var BLACK_PAWN = 0x09;
var BLACK_KNIGHT = 0x0A;
var BLACK_BISHOP = 0x0B;
var BLACK_ROOK = 0x0C;
var BLACK_QUEEN = 0x0D;
var BLACK_KING = 0x0E;
// Allandok
var FLAG_EXACT = 3; // Hash zaszlo 3
var FLAG_UPPER = 2; // Hash zaszlo 2
var FLAG_LOWER = 1; // Hash zaszlo 1
var FLAG_NONE = 0; // Hash zaszlo 0
var NOMOVE = 0; // Nincs lepes 0
var DEPTH_ZERO = 0; // Nulla melyseg
var NOT_IN_CHECK = 0; // Nincs Sakkban
var EN_PASSANT = 0; // En passant mezo
var INFINITE = 30000; // Infinity / Vegtelen
var CAPTURE_MASK = 0x1000; // Leutes jelzo maszk
var DANGER_MASK = 0x3F000; // Fontos lepes maszk
var CASTLED_MASK = 0x20000; // Sancolas jelzo maszk
var TACTICAL_MASK = 0x1F000; // Utes, Bevaltas maszk
var ISMATE = INFINITE - MaxDepth * 2; // Matt
var PAWNENTRIES = (1 << 12) / 1; // Gyalog hash max ~1 MB
var PAWNMASK = PAWNENTRIES - 1; // Gyalog hash maszk, csak ketto hatvanya lehet
var HASHENTRIES = (32 << 20) / 16; // Hashtabla merete 32 MB / 1 Hash merete (16 byte)
var HASHMASK = HASHENTRIES - 4; // Hashtabla maszk, csak ketto hatvanya lehet & MASK
var CASTLEBIT = { WQ : 1, WK : 2, BQ : 4, BK : 8, W : 3, B : 12 }; // Sanc-ellenorzes
var MvvLvaScores = [ 0, 1, 2, 3, 4, 5, 6, 0, 0, 1, 2, 3, 4, 5, 6 ]; // Mvv-Lva Babuk erteke
var SeeValue = [ 0, 100, 325, 325, 500, 975, 20000, 0, 0, 100, 325, 325, 500, 975, 20000 ];
var KnightMoves = [ 14, -14, 18, -18, 31, -31, 33, -33 ]; // Huszar lepesek
var KingMoves = [ 1, -1, 15, -15, 16, -16, 17, -17 ]; // Kiraly lepesek
var BishopMoves = [ 15, -15, 17, -17 ]; // Futo lepesek
var RookMoves = [ 1, -1, 16, -16 ]; // Bastya lepesek
var Letters = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' ]; // Betuzes
var START_FEN = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -';
var nonSlider = [ 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1 ]; // nonSlider (P, N, K)
var PieceDir = [ 0, 0, KnightMoves, BishopMoves, RookMoves, KingMoves, KingMoves ]; // Lepesek tomb
var RANKS = { RANK_1 : 1, RANK_2 : 2, RANK_3 : 3, RANK_4 : 4, RANK_5 : 5, RANK_6 : 6, RANK_7 : 7, RANK_8 : 8 }; // Sorok
var FILES = { FILE_A : 1, FILE_B : 2, FILE_C : 3, FILE_D : 4, FILE_E : 5, FILE_F : 6, FILE_G : 7, FILE_H : 8 }; // Oszlopok
// Typed Arrays for better memory usage. (16 byte)
var hash_move = new Uint32Array(HASHENTRIES);
var hash_date = new Uint16Array(HASHENTRIES);
var hash_eval = new Int16Array (HASHENTRIES);
var hash_lock = new Int32Array (HASHENTRIES);
var hash_score = new Int16Array (HASHENTRIES);
var hash_flags = new Uint8Array (HASHENTRIES);
var hash_depth = new Uint8Array (HASHENTRIES);
// BitBoard
var LOW = 0; // Also 32 bit tomb index
var HIGH = 1; // Felso 32 bit tomb index
var RankBBMask = new Array(9); // Bitboard sor maszk
var FileBBMask = new Array(9); // Bitboard oszlop maszk
var SetMask = new Array(64); // Bitboard Mentes maszk
var ClearMask = new Array(64); // Bitboard Torles maszk
var HighSQMask = new Array(64); // Bitboard HighSQ maszk
var BitFixLow = new Array(64); // Bitboard BitFix maszk [LOW]
var BitFixHigh = new Array(64); // Bitboard BitFix maszk [HIGH]
var IsolatedMask = new Array(64); // Bitboard Isolated maszk
var WhitePassedMask = new Array(64); // Bitboard Passed maszk Feher
var BlackPassedMask = new Array(64); // Bitboard Passed maszk Fekete
var WOpenFileMask = new Array(64); // Bitboard OpenFile maszk Feher
var BOpenFileMask = new Array(64); // Bitboard OpenFile maszk Fekete
var NeighbourMask = new Array(64); // Bitboard Neighbour maszk Kozos
var BlockerBBMask = new Array(64 * 8 * 2); // Szelek kizaras maszk
var AttackBBMask = new Array(64 * 8 * 2); // Tamadas tombok maszk
var BehindBBMask = new Array(64 * 64 * 2); // A mezo mogotti maszk
var BetweenBBMask = new Array(64 * 64 * 2); // Ket mezo kozti maszk
var BitBoard = new Array(30); // Index: color/pce << 1 | Low/High
var WhiteLow = WHITE << 1 | LOW;
var WhiteHigh = WHITE << 1 | HIGH;
var wPawnLow = WHITE_PAWN << 1 | LOW;
var wKnightLow = WHITE_KNIGHT << 1 | LOW;
var wBishopLow = WHITE_BISHOP << 1 | LOW;
var wRookLow = WHITE_ROOK << 1 | LOW;
var wQueenLow = WHITE_QUEEN << 1 | LOW;
var wKingLow = WHITE_KING << 1 | LOW;
var wPawnHigh = WHITE_PAWN << 1 | HIGH;
var wKnightHigh = WHITE_KNIGHT << 1 | HIGH;
var wBishopHigh = WHITE_BISHOP << 1 | HIGH;
var wRookHigh = WHITE_ROOK << 1 | HIGH;
var wQueenHigh = WHITE_QUEEN << 1 | HIGH;
var wKingHigh = WHITE_KING << 1 | HIGH;
var BlackLow = BLACK << 1 | LOW;
var BlackHigh = BLACK << 1 | HIGH;
var bPawnLow = BLACK_PAWN << 1 | LOW;
var bKnightLow = BLACK_KNIGHT << 1 | LOW;
var bBishopLow = BLACK_BISHOP << 1 | LOW;
var bRookLow = BLACK_ROOK << 1 | LOW;
var bQueenLow = BLACK_QUEEN << 1 | LOW;
var bKingLow = BLACK_KING << 1 | LOW;
var bPawnHigh = BLACK_PAWN << 1 | HIGH;
var bKnightHigh = BLACK_KNIGHT << 1 | HIGH;
var bBishopHigh = BLACK_BISHOP << 1 | HIGH;
var bRookHigh = BLACK_ROOK << 1 | HIGH;
var bQueenHigh = BLACK_QUEEN << 1 | HIGH;
var bKingHigh = BLACK_KING << 1 | HIGH;
// Mezok elnevezese
var SQUARES = { A8: 0, B8: 1, C8: 2, D8: 3, E8: 4, F8: 5, G8: 6, H8: 7,
A7: 8, B7: 9, C7: 10, D7: 11, E7: 12, F7: 13, G7: 14, H7: 15,
A6: 16, B6: 17, C6: 18, D6: 19, E6: 20, F6: 21, G6: 22, H6: 23,
A5: 24, B5: 25, C5: 26, D5: 27, E5: 28, F5: 29, G5: 30, H5: 31,
A4: 32, B4: 33, C4: 34, D4: 35, E4: 36, F4: 37, G4: 38, H4: 39,
A3: 40, B3: 41, C3: 42, D3: 43, E3: 44, F3: 45, G3: 46, H3: 47,
A2: 48, B2: 49, C2: 50, D2: 51, E2: 52, F2: 53, G2: 54, H2: 55,
A1: 56, B1: 57, C1: 58, D1: 59, E1: 60, F1: 61, G1: 62, H1: 63 };
// Kezdeti allapot
var CHESS_BOARD = [ BLACK_ROOK, BLACK_KNIGHT, BLACK_BISHOP, BLACK_QUEEN, BLACK_KING, BLACK_BISHOP, BLACK_KNIGHT, BLACK_ROOK,
BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
WHITE_PAWN, WHITE_PAWN, WHITE_PAWN, WHITE_PAWN, WHITE_PAWN, WHITE_PAWN, WHITE_PAWN, WHITE_PAWN,
WHITE_ROOK, WHITE_KNIGHT, WHITE_BISHOP, WHITE_QUEEN, WHITE_KING, WHITE_BISHOP, WHITE_KNIGHT, WHITE_ROOK ];
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function InitEvalMasks() {
if (SetMask[1] != undefined) { // Mar inicializaltunk!
return false;
}
var sq, sq2, pce, from;
// Sor + Oszlop nullazas
for (sq = 0; sq < 8; sq++) {
FileBBMask[sq] = 0;
RankBBMask[sq] = 0;
}
// Sor + Oszlop feltoltes
for (var r = RANKS.RANK_8; r >= RANKS.RANK_1; r--)
for (var f = FILES.FILE_H; f >= FILES.FILE_A; f--) {
sq = (r - 1) * 8 + (8 - f);
FileBBMask[f] |= (1 << sq);
RankBBMask[r] |= (1 << sq);
}
// Bitmaszkok nullazasa
for (sq = 0; sq < 64; sq++)
{
IsolatedMask [sq] = 0;
WOpenFileMask [sq] = 0;
BOpenFileMask [sq] = 0;
NeighbourMask [sq] = 0;
WhitePassedMask[sq] = 0;
BlackPassedMask[sq] = 0;
// Tamadasok + Kizarasok
for (pce = KNIGHT; pce <= KING; pce++) {
AttackBBMask [AttackBBidx(pce, sq, LOW)] = 0;
AttackBBMask [AttackBBidx(pce, sq, HIGH)] = 0;
BlockerBBMask[AttackBBidx(pce, sq, LOW)] = 0;
BlockerBBMask[AttackBBidx(pce, sq, HIGH)] = 0;
}
// Mogotte + Koztes
for (sq2 = 0; sq2 < 64; sq2++) {
BehindBBMask [BetweenBBidx(sq, sq2, LOW)] = 0;
BehindBBMask [BetweenBBidx(sq, sq2, HIGH)] = 0;
BetweenBBMask[BetweenBBidx(sq, sq2, LOW)] = 0;
BetweenBBMask[BetweenBBidx(sq, sq2, HIGH)] = 0;
}
// Maszkok feltoltese
SetMask [sq] = (1 << (sq > 31 ? 63-sq : 31-sq)); // SetMask
ClearMask [sq] = ~SetMask[sq]; // ClearMask
HighSQMask[sq] = (sq > 31 ? HIGH : LOW); // HighSQMask
BitFixLow [sq] = (sq > 31 ? 63 : 32 + sq); // Also bit fix?(63-Igen)
BitFixHigh[sq] = (sq > 31 ? sq - 32 : 0); // Felso bit kell?(0-Nem)
// Mezo tavolsag
DISTANCE[sq] = new Array(64);
var rank1 = TableRanks[sq];
var file1 = TableFiles[sq];
for (sq2 = 0; sq2 < 64; sq2++) {
var rank2 = TableRanks[sq2];
var file2 = TableFiles[sq2];
DISTANCE[sq][sq2] = Math.max(Math.abs(rank1-rank2), Math.abs(file1-file2));
}
}
// Bitmaszkok feltoltese
for (from = 0; from < 64; from++)
{
for (sq = from + 8; sq < 64; sq += 8) {
BOpenFileMask [from] |= SetMask[sq];
BlackPassedMask[from] |= SetMask[sq];
}
for (sq = from - 8; sq >= 0; sq -= 8) {
WOpenFileMask [from] |= SetMask[sq];
WhitePassedMask[from] |= SetMask[sq];
}
if (TableFiles[from] != FILES.FILE_A) {
NeighbourMask[from] |= SetMask[from - 1];
IsolatedMask [from] |= FileBBMask[TableFiles[from] - 1];
for (sq = from + 7; sq < 64; sq += 8) {
BlackPassedMask[from] |= SetMask[sq];
}
for (sq = from - 9; sq >= 0; sq -= 8) {
WhitePassedMask[from] |= SetMask[sq];
}
}
if (TableFiles[from] != FILES.FILE_H) {
NeighbourMask[from] |= SetMask[from + 1];
IsolatedMask [from] |= FileBBMask[TableFiles[from] + 1];
for (sq = from + 9; sq < 64; sq += 8) {
BlackPassedMask[from] |= SetMask[sq];
}
for (sq = from - 7; sq >= 0; sq -= 8) {
WhitePassedMask[from] |= SetMask[sq];
}
}
// Mobilitas: Gyalog tamadasokat a NeighbourMask adja!
var from88 = to_88(from); // 64 -> 120
for (pce = KNIGHT; pce <= KING; pce++)
{
for (var dir = 0; dir < PieceDir[pce].length; dir++)
{
var delta = PieceDir[pce][dir];
for (var next88 = from88 + delta; !(next88 & 0x88); next88 += delta)
{
var next = from_88(next88); // 120 -> 64
AttackBBMask[AttackBBidx(pce, from, HighSQMask[next])] |= SetMask[next]; // Tamadas
if (pce === QUEEN) {
for (sq = from88 + delta; !(sq & 0x88) && sq != next88; sq += delta) {
BetweenBBMask[BetweenBBidx(from, next, HighSQMask[from_88(sq)])] |= SetMask[from_88(sq)]; // Koztes
}
for (sq = next88 + delta; !(sq & 0x88); sq += delta) {
BehindBBMask[BetweenBBidx(from, next, HighSQMask[from_88(sq)])] |= SetMask[from_88(sq)]; // Mogotte
}
}
if (nonSlider[pce]) break; // Pawn, Knight, King
}
}
}
}
// Szeleket kizaro tomb
for (from = 0; from < 64; from++)
{
for (pce = KNIGHT; pce <= KING; pce++)
{
var attacks = PceAttacks(pce, from);
for (var bb = attacks.Low; bb != 0; bb = restBit(bb)) {
sq = firstBitLow(bb);
if ((attacks.Low & BehindBBMask[BetweenBBidx(from, sq, LOW)]) != 0
|| (attacks.High & BehindBBMask[BetweenBBidx(from, sq, HIGH)]) != 0) {
BlockerBBMask[AttackBBidx(pce, from, LOW)] |= SetMask[sq];
}
}
for (var bb = attacks.High; bb != 0; bb = restBit(bb)) {
sq = firstBitHigh(bb);
if ((attacks.Low & BehindBBMask[BetweenBBidx(from, sq, LOW)]) != 0
|| (attacks.High & BehindBBMask[BetweenBBidx(from, sq, HIGH)]) != 0) {
BlockerBBMask[AttackBBidx(pce, from, HIGH)] |= SetMask[sq];
}
}
}
}
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function BinaryString(nMask) {
for (var nFlag = 0, nShifted = nMask, sMask = ''; nFlag < 32;
nFlag++, sMask += String(nShifted >>> 31), nShifted <<= 1);
return sMask;
}
function PrintBitBoard(BitLow, BitHigh) {
var msg = '', index = 0;
console.log('Also: '+BinaryString(BitLow));
console.log('Felso: '+BinaryString(BitHigh));
var BitBoard = BinaryString(BitLow);
BitBoard += BinaryString(BitHigh);
BitBoard = BitBoard.split('');
for (var rank = RANKS.RANK_8; rank >= RANKS.RANK_1; rank--) {
msg = rank+'. ';
for (var file = FILES.FILE_A; file <= FILES.FILE_H; file++) {
if (BitBoard[index++] == '1') {
msg += 'X';
} else {
msg += '-';
}
}
console.log(msg);
}
}
function restBit(b) {
return b & (b - 1);
}
var BitIndexLow = [ // Mezok 0-31-ig
31, 30, 3, 29, 2, 17, 7, 28, 1, 9, 11, 16, 6, 14, 27, 23,
0, 4, 18, 8, 10, 12, 15, 24, 5, 19, 13, 25, 20, 26, 21, 22 ];
function firstBitLow(b) {
return BitIndexLow[((b & -b) * 0x077CB531) >>> 27];
}
var BitIndexHigh = [ // Mezok 32-63-ig
63, 62, 35, 61, 34, 49, 39, 60, 33, 41, 43, 48, 38, 46, 59, 55,
32, 36, 50, 40, 42, 44, 47, 56, 37, 51, 45, 57, 52, 58, 53, 54 ];
function firstBitHigh(b) {
return BitIndexHigh[((b & -b) * 0x077CB531) >>> 27];
}
function PopCount(b) { // for 32 bit
b = b - ((b >>> 1) & 0x55555555);
b = (b & 0x33333333) + ((b >>> 2) & 0x33333333);
return ((b + (b >>> 4) & 0x0F0F0F0F) * 0x01010101) >>> 24;
}
function SetBitBoard(sq, pce, color) {
BitBoard[pce << 1 | HighSQMask[sq]] |= SetMask[sq];
BitBoard[color << 1 | HighSQMask[sq]] |= SetMask[sq];
}
function ClearBitBoard(sq, pce, color) {
BitBoard[pce << 1 | HighSQMask[sq]] &= ClearMask[sq];
BitBoard[color << 1 | HighSQMask[sq]] &= ClearMask[sq];
}
function DefendedByPawn(sq, sd) {
return sd === WHITE ? DefendedByWPawn(sq) : DefendedByBPawn(sq);
}
function DefendedByBPawn(sq) {
sq = Math.max(sq - 8, 0);
return (NeighbourMask[sq] & BitBoard[BLACK_PAWN << 1 | HighSQMask[sq]]);
}
function DefendedByWPawn(sq) {
sq = Math.min(sq + 8, 63);
return (NeighbourMask[sq] & BitBoard[WHITE_PAWN << 1 | HighSQMask[sq]]);
}
function DirectNeighborPawn(sq, sd) {
return (NeighbourMask[sq] & BitBoard[(sd | PAWN) << 1 | HighSQMask[sq]]);
}
function PawnControlled(sq, sd, xd) {
return PopCount(DefendedByPawn(sq, sd)) >= PopCount(DefendedByPawn(sq, xd));
}
function PawnSafeSquare(sq, sd, xd) {
// return (CHESS_BOARD[sq] & 0x07) !== PAWN && PawnControlled(sq, sd, xd);
return (CHESS_BOARD[sq] & 0x07) !== PAWN && DefendedByPawn(sq, xd) == 0;
}
function WeakPawn(sq, rank, file, us, them) {
var inc = us ? 8 : -8;
var usPawn = us | PAWN;
var Rank_2 = us ? RANKS.RANK_7 : RANKS.RANK_2;
var Rank_5 = us ? RANKS.RANK_4 : RANKS.RANK_5;
// Hatrahagyott Gyalog..?
var s1 = sq + inc; // Elottunk 1. mezo
var s2 = s1 + inc; // Elottunk 2. mezo
if (DirectNeighborPawn(s1, us)
&& PawnSafeSquare(s1, us, them)) {
return false;
}
if (rank == Rank_2
&& DirectNeighborPawn(s2, us)
&& PawnSafeSquare(s1, us, them)
&& PawnSafeSquare(s2, us, them)) {
return false;
}
// Eloretolt Gyalog..?
if (file != FILES.FILE_A) { // Bal oldali vedo
var s0 = sq - 1; // Bal oldal
var s1 = s0 - inc; // Balra lent 1. mezo
var s2 = s1 - inc; // Balra lent 2. mezo
var s3 = s2 - inc; // Balra lent 3. mezo
if (CHESS_BOARD[s2] === usPawn
&& PawnSafeSquare(s1, us, them)) {
return false;
}
if (rank == Rank_5
&& CHESS_BOARD[s3] === usPawn
&& PawnSafeSquare(s1, us, them)
&& PawnSafeSquare(s2, us, them)) {
return false;
}
}
if (file != FILES.FILE_H) { // Jobb oldali vedo
var s0 = sq + 1; // Jobb oldal
var s1 = s0 - inc; // Jobbra lent 1. mezo
var s2 = s1 - inc; // Jobbra lent 2. mezo
var s3 = s2 - inc; // Jobbra lent 3. mezo
if (CHESS_BOARD[s2] === usPawn
&& PawnSafeSquare(s1, us, them)) {
return false;
}
if (rank == Rank_5
&& CHESS_BOARD[s3] === usPawn
&& PawnSafeSquare(s1, us, them)
&& PawnSafeSquare(s2, us, them)) {
return false;
}
}
return true;
}
function WhiteMostPawn(sq) { // Legelso Feher Gyalog
return (WOpenFileMask[sq] & BitBoard[wPawnLow]) | (WOpenFileMask[BitFixHigh[sq]] & BitBoard[wPawnHigh]);
}
function BlackMostPawn(sq) { // Legelso Fekete Gyalog
return (BOpenFileMask[BitFixLow[sq]] & BitBoard[bPawnLow]) | (BOpenFileMask[sq] & BitBoard[bPawnHigh]);
}
function WhiteOpenFile(sq) { // Fekete Dupla Gyalog: WhiteOpenFile(sq) != 0
return (WOpenFileMask[sq] & BitBoard[bPawnLow]) | (WOpenFileMask[BitFixHigh[sq]] & BitBoard[bPawnHigh]);
}
function BlackOpenFile(sq) { // Feher Dupla Gyalog: BlackOpenFile(sq) != 0
return (BOpenFileMask[BitFixLow[sq]] & BitBoard[wPawnLow]) | (BOpenFileMask[sq] & BitBoard[wPawnHigh]);
}
function WhitePassedPawn(sq) {
return (WhitePassedMask[sq] & BitBoard[bPawnLow]) | (WhitePassedMask[BitFixHigh[sq]] & BitBoard[bPawnHigh]);
}
function BlackPassedPawn(sq) {
return (BlackPassedMask[BitFixLow[sq]] & BitBoard[wPawnLow]) | (BlackPassedMask[sq] & BitBoard[wPawnHigh]);
}
function IsOpenFile(file, color) {
return (FileBBMask[file] & BitBoard[(color|PAWN) << 1 | LOW]) | (FileBBMask[file] & BitBoard[(color|PAWN) << 1 | HIGH]);
}
function IsolatedPawn(sq, color) {
return (IsolatedMask[sq] & BitBoard[(color|PAWN) << 1 | LOW]) | (IsolatedMask[sq] & BitBoard[(color|PAWN) << 1 | HIGH]);
}
function PawnOnSeventh() {
return (CurrentPlayer ? (BitBoard[bPawnHigh] & RankBBMask[RANKS.RANK_2]) : (BitBoard[wPawnLow] & RankBBMask[RANKS.RANK_7]));
}
function PawnPush(Move) {
return (CHESS_BOARD[FROMSQ(Move)] & 0x07) == PAWN && (CurrentPlayer ? (TableRanks[TOSQ(Move)] <= RANKS.RANK_3 && BlackPassedPawn(TOSQ(Move)) == 0)
: (TableRanks[TOSQ(Move)] >= RANKS.RANK_6 && WhitePassedPawn(TOSQ(Move)) == 0));
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function to_88(sq) { return sq + (sq & 56); }
function from_88(sq) { return (sq + (sq & 0x07)) >> 1; }
function BetweenBBidx(s1, s2, bit) { return (s1 << 7) | (s2 << 1) | bit; }
function AttackBBidx(pce, sq, bit) { return (sq << 4) | (pce << 1) | bit; }
function LineIsEmpty(s1, s2, pieces) {
return (pieces.Low & BetweenBBMask[BetweenBBidx(s1, s2, LOW)]) | (pieces.High & BetweenBBMask[BetweenBBidx(s1, s2, HIGH)]);
}
function GetAllPce() {
return { Low : (BitBoard[WhiteLow] | BitBoard[BlackLow]), High : (BitBoard[WhiteHigh] | BitBoard[BlackHigh]) };
}
function PceBlocker(pce, sq) {
return { Low : BlockerBBMask[AttackBBidx(pce, sq, LOW)], High : BlockerBBMask[AttackBBidx(pce, sq, HIGH)] };
}
function PceAttacks(pce, sq) {
return { Low : AttackBBMask[AttackBBidx(pce, sq, LOW)], High : AttackBBMask[AttackBBidx(pce, sq, HIGH)] };
}
function Behind(s1, s2) {
return { Low : BehindBBMask[BetweenBBidx(s1, s2, LOW)], High : BehindBBMask[BetweenBBidx(s1, s2, HIGH)] };
}
function AllPceByColor(color) {
return { Low : BitBoard[color << 1 | LOW], High : BitBoard[color << 1 | HIGH] };
}
function KingZone(Ring, Rank, File) { // 3x3 square
if (Rank == RANKS.RANK_1) {
Ring.High |= Ring.High << 8;
} else if (Rank == RANKS.RANK_8) {
Ring.Low |= Ring.Low >>> 8;
}
if (File == FILES.FILE_A) {
Ring.Low |= Ring.Low >>> 1;
Ring.High |= Ring.High >>> 1;
} else if (File == FILES.FILE_H) {
Ring.Low |= Ring.Low << 1;
Ring.High |= Ring.High << 1;
}
}
function AttacksFrom(pce, from, pieces) { // Based on Senpai!
var bb, sq;
var attacks = PceAttacks(pce, from);
var blocker = PceBlocker(pce, from);
for (bb = pieces.Low & blocker.Low; bb != 0; bb = restBit(bb)) {
sq = firstBitLow(bb);
attacks.Low &= ~BehindBBMask[BetweenBBidx(from, sq, LOW)];
attacks.High &= ~BehindBBMask[BetweenBBidx(from, sq, HIGH)];
}
for (bb = pieces.High & blocker.High; bb != 0; bb = restBit(bb)) {
sq = firstBitHigh(bb);
attacks.Low &= ~BehindBBMask[BetweenBBidx(from, sq, LOW)];
attacks.High &= ~BehindBBMask[BetweenBBidx(from, sq, HIGH)];
}
return attacks;
}
function wPawnAttacks(attacks) {
// Hack: backward instead of forward on white side!
attacks.High |= ((BitBoard[wPawnHigh] & ~FileBBMask[FILES.FILE_A]) >>> 7) | ((BitBoard[wPawnHigh] & ~FileBBMask[FILES.FILE_H]) >>> 9);
attacks.Low |= ((BitBoard[wPawnLow] & ~FileBBMask[FILES.FILE_H]) << 7) | ((BitBoard[wPawnLow] & ~FileBBMask[FILES.FILE_A]) << 9);
attacks.Low |= (attacks.High >>> 16); // Add 5th rank attacks to Low
attacks.High <<= 16; // Hack: forward 2x
}
function bPawnAttacks(attacks) {
// Hack: backward instead of forward on black side!
attacks.Low |= ((BitBoard[bPawnLow] & ~FileBBMask[FILES.FILE_H]) << 7) | ((BitBoard[bPawnLow] & ~FileBBMask[FILES.FILE_A]) << 9);
attacks.High |= ((BitBoard[bPawnHigh] & ~FileBBMask[FILES.FILE_A]) >>> 7) | ((BitBoard[bPawnHigh] & ~FileBBMask[FILES.FILE_H]) >>> 9);
attacks.High |= (attacks.Low << 16); // Add 4th rank attacks to High
attacks.Low >>>= 16; // Hack: forward 2x
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function validateMove(from, to, side) { // for TanKy UI
var forceMove = CurrentPlayer != side;
var fromPiece = CHESS_BOARD[from];
var toPiece = CHESS_BOARD[to];
if (!fromPiece) { // Moving an empty square?
return false;
}
if ((fromPiece & 0x8) ^ side) { // Not your turn!
return false;
}
if (!forceMove && toPiece && (toPiece & 0x8) == side) { // Cannot attack one of your own!
return false;
}
var pieceType = fromPiece & 0x07;
// Capture move..?
var capture = 0;
if (toPiece || (pieceType === PAWN && EN_PASSANT != 0 && EN_PASSANT == to)) {
capture = 1;
}
// Promotion..?
var promote = 0;
if (pieceType === PAWN && (to <= SQUARES.H8 || to >= SQUARES.A1)) {
promote = side|QUEEN;
}
// Casling..?
var castling = 0;
if (pieceType === KING && Math.abs(from - to) === 2) {
castling = 1;
}
// Create move..
var Move = BIT_MOVE(from, to, capture, promote, castling);
// Legal move..?
if (!forceMove)
{
for (var index = brd_moveStart[0]; index < brd_moveStart[1]; index++) {
if (brd_moveList[index] == Move) {
return isLegal(Move);
}
}
return false;
}
else if (castling === 1)
{
return side === WHITE ? (to == SQUARES.G1 && CastleRights & CASTLEBIT.WK) || (to == SQUARES.C1 && CastleRights & CASTLEBIT.WQ)
: (to == SQUARES.G8 && CastleRights & CASTLEBIT.BK) || (to == SQUARES.C8 && CastleRights & CASTLEBIT.BQ);
}
else if (pieceType === PAWN)
{
var attacks = { Low : 0, High : 0 };
var inc = side ? 8 : -8, next = from + inc;
HighSQMask[next] ? attacks.High = SetMask[next] | NeighbourMask[next]
: attacks.Low = SetMask[next] | NeighbourMask[next];
if (TableRanks[from] == (side ? RANKS.RANK_7 : RANKS.RANK_2))
{
HighSQMask[next + inc] ? attacks.High |= SetMask[next + inc]
: attacks.Low |= SetMask[next + inc];
}
}
else
{
var attacks = PceAttacks(pieceType, from);
}
return HighSQMask[to] ? (attacks.High & SetMask[to]) != 0 : (attacks.Low & SetMask[to]) != 0;
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function StoreHash(move, score, _eval, flags, depth) { // Hash mentes
var index = brd_hashKeyLow & HASHMASK;
var oldest = -1;
var update = 0;
for (var entry = index; entry < index + 4; entry++) {
if (hash_lock[entry] == brd_hashKeyHigh) {
if (hash_depth[entry] <= depth) {
if (move == NOMOVE) move = hash_move[entry];
update = entry;
break;
}
if (hash_move[entry] == NOMOVE) { // fill entry with move!
hash_move[entry] = move;
}
hash_date[entry] = HashDate; // update age of deeper entry!
return;
}
var age = (HashDate - hash_date[entry]) * 64 + 64 - hash_depth[entry];
if (oldest < age) {
oldest = age;
update = entry;
}
}
if (hash_lock[update] == 0) { // new
HashUsed++;
}
if (score > ISMATE) {
score += BoardPly;
} else if (score < -ISMATE) {
score -= BoardPly;
}
hash_move [update] = move;
hash_eval [update] = _eval;
hash_score[update] = score;
hash_flags[update] = flags;
hash_depth[update] = depth;
hash_date [update] = HashDate;
hash_lock [update] = brd_hashKeyHigh;
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function ProbeHash() { // Hash kiolvasas
var index = brd_hashKeyLow & HASHMASK;
for (var entry = index; entry < index + 4; entry++) {
if (hash_lock[entry] == brd_hashKeyHigh) {
return {
move : hash_move [entry],
eval : hash_eval [entry],
score : hash_score[entry],
flags : hash_flags[entry],
depth : hash_depth[entry]
};
}
}
return NOMOVE;
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function IsRepetition() { // Lepesismetles + 50 lepesszabaly
if (brd_fiftyMove >= 100) { // TODO: mate?
return true;
}
for (var index = 4; index <= brd_fiftyMove; index += 2) {
if (MOVE_HISTORY[MoveCount-index].hashKeyLow == brd_hashKeyLow
&& MOVE_HISTORY[MoveCount-index].hashKeyHigh == brd_hashKeyHigh) {
return true;
}
}
return false;
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function FROMSQ(m) { return (m & 0x3F); }
function TOSQ(m) { return ((m >> 6) & 0x3F); }
function PROMOTED(m) { return ((m >> 13) & 0xF); }
function HASH_SIDE() {
brd_hashKeyLow ^= SideKeyLow;
brd_hashKeyHigh ^= SideKeyHigh;
}
function HASH_PCE(pce, sq) {
brd_hashKeyLow ^= PieceKeysLow [(pce << 6) | sq];
brd_hashKeyHigh ^= PieceKeysHigh[(pce << 6) | sq];
if ((pce & 0x07) === PAWN) {
brd_pawnKeyLow ^= PieceKeysLow [(pce << 6) | sq];
brd_pawnKeyHigh ^= PieceKeysHigh[(pce << 6) | sq];
}
}
function HASH_CA() {
brd_hashKeyLow ^= CastleKeysLow [CastleRights];
brd_hashKeyHigh ^= CastleKeysHigh[CastleRights];
}
function HASH_EP() {
brd_hashKeyLow ^= PieceKeysLow [EN_PASSANT];
brd_hashKeyHigh ^= PieceKeysHigh[EN_PASSANT];
}
function MOVE_PCE(pce, from, to) {
CHESS_BOARD[from] = 0; // Babu torlese
CHESS_BOARD[to] = pce; // Babu mozgatas
brd_pieceIndex[to] = brd_pieceIndex[from];
brd_pieceList[(pce << 4) | brd_pieceIndex[to]] = to;
ClearBitBoard(from, pce, (pce & 0x8));
SetBitBoard(to, pce, (pce & 0x8));
}
function ADDING_PCE(pce, sq, currentPlayer) {
CHESS_BOARD[sq] = pce; // Babu hozzadasa
brd_pieceIndex[sq] = brd_pieceCount[pce];
brd_pieceList[(pce << 4) | brd_pieceIndex[sq]] = sq;
brd_Material[currentPlayer] += PieceValue[pce];
brd_pieceCount[pce]++; // Darabszam novelese
SetBitBoard(sq, pce, currentPlayer);
}
function DELETE_PCE(pce, sq, currentPlayer) {
CHESS_BOARD[sq] = 0; // Babu torlese
brd_pieceCount[pce]--; // Darabszam csokkentese
var lastPceSquare = brd_pieceList[(pce << 4) | brd_pieceCount[pce]];
brd_pieceIndex[lastPceSquare] = brd_pieceIndex[sq];
brd_pieceList[(pce << 4) | brd_pieceIndex[lastPceSquare]] = lastPceSquare;
brd_pieceList[(pce << 4) | brd_pieceCount[pce]] = EMPTY; // Ures
brd_Material[currentPlayer] -= PieceValue[pce];
ClearBitBoard(sq, pce, currentPlayer);
}
function BIT_MOVE(from, to, captured, promoted, castled) {
return (from | (to << 6) | (captured << 12) | (promoted << 13) | (castled << 17)); // Lepes: 18 bit
}
/*
0000 0000 0000 0011 1111 -> Ahonnan lepunk (m & 0x3F)
0000 0000 1111 1100 0000 -> Ahova lepunk ((m >> 6) & 0x3F)
0000 0001 0000 0000 0000 -> Leutes jelzes (m & CAPTURE_MASK)
0001 1110 0000 0000 0000 -> Gyalog bevaltas ((m >> 13) & 0xF)
0010 0000 0000 0000 0000 -> Sancolas jelzes (m & CASTLED_MASK)
-----------------------------------------------------------------
0001 1111 0000 0000 0000 -> Utes vagy Bevaltas (m & TACTICAL_MASK)
0011 1111 0000 0000 0000 -> Utes, Bevaltas, Sanc (m & DANGER_MASK)
*/
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function makeMove(move) {
var to = TOSQ(move);
var from = FROMSQ(move);
var MOVED_PIECE = CHESS_BOARD[from];
var PROMOTED_PIECE = PROMOTED(move);
var CAPTURED_PIECE = CHESS_BOARD[to];
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
MOVE_HISTORY[MoveCount] = { // Lepeselozmeny mentese
NN_HIDDEN_L : NN_HIDDEN_LAYER.slice(0), // copy!
capturedPCE : CAPTURED_PIECE,
hashKeyHigh : brd_hashKeyHigh,
pawnKeyHigh : brd_pawnKeyHigh,
hashKeyLow : brd_hashKeyLow,
pawnKeyLow : brd_pawnKeyLow,
fiftyMove : brd_fiftyMove,
castleBIT : CastleRights,
epSquare : EN_PASSANT,
move : move
};
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
brd_fiftyMove++; // 50 lepes szabaly
if (EN_PASSANT != 0) HASH_EP(); // En Passant hashKey
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
if (CAPTURED_PIECE) // Ha leutottunk valakit
{
brd_fiftyMove = 0; // 50 lepes nullazasa
HASH_PCE(CAPTURED_PIECE, to);
DELETE_PCE(CAPTURED_PIECE, to, (CurrentPlayer^8));
DELETE_NN_PCE(CAPTURED_PIECE, to, (CurrentPlayer^8));
}
else if (move & CAPTURE_MASK) // En Passant Lepes
{
if (CurrentPlayer) // Fekete
{
EN_PASSANT = to-8; // Hack: Koztes tarolo
HASH_PCE(WHITE_PAWN, EN_PASSANT);
DELETE_PCE(WHITE_PAWN, EN_PASSANT, WHITE);
DELETE_NN_PCE(WHITE_PAWN, EN_PASSANT, WHITE);
}
else // Feher
{
EN_PASSANT = to+8; // Hack: Koztes tarolo
HASH_PCE(BLACK_PAWN, EN_PASSANT);
DELETE_PCE(BLACK_PAWN, EN_PASSANT, BLACK);
DELETE_NN_PCE(BLACK_PAWN, EN_PASSANT, BLACK);
}
}
else if (move & CASTLED_MASK) // Sancolaskor Bastya mozgatasa
{
switch (to) {
case SQUARES.C1:
HASH_PCE(WHITE_ROOK, SQUARES.A1);
HASH_PCE(WHITE_ROOK, SQUARES.D1);
MOVE_PCE(WHITE_ROOK, SQUARES.A1, SQUARES.D1);
MOVE_NN_PCE(WHITE_ROOK, SQUARES.A1, SQUARES.D1);
break;
case SQUARES.C8:
HASH_PCE(BLACK_ROOK, SQUARES.A8);
HASH_PCE(BLACK_ROOK, SQUARES.D8);
MOVE_PCE(BLACK_ROOK, SQUARES.A8, SQUARES.D8);
MOVE_NN_PCE(BLACK_ROOK, SQUARES.A8, SQUARES.D8);
break;
case SQUARES.G1:
HASH_PCE(WHITE_ROOK, SQUARES.H1);
HASH_PCE(WHITE_ROOK, SQUARES.F1);
MOVE_PCE(WHITE_ROOK, SQUARES.H1, SQUARES.F1);
MOVE_NN_PCE(WHITE_ROOK, SQUARES.H1, SQUARES.F1);
break;
case SQUARES.G8:
HASH_PCE(BLACK_ROOK, SQUARES.H8);
HASH_PCE(BLACK_ROOK, SQUARES.F8);
MOVE_PCE(BLACK_ROOK, SQUARES.H8, SQUARES.F8);
MOVE_NN_PCE(BLACK_ROOK, SQUARES.H8, SQUARES.F8);
break;
default: break;
}
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
EN_PASSANT = 0; // En passant torles
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
if ((MOVED_PIECE & 0x07) === PAWN) // Ha Gyaloggal leptunk
{
brd_fiftyMove = 0; // 50 lepes nullazasa
if (Math.abs(from - to) === 16) // En Passant mentese
{
EN_PASSANT = (to + (CurrentPlayer ? -8 : 8));
HASH_EP(); // En Passant hashKey