Both sides previous revisionPrevious revisionNext revision | Previous revision |
chess:programming:move_generation [2021/10/28 00:09] – peter | chess:programming:move_generation [2021/11/15 16:18] (current) – peter |
---|
====== Chess - Programming - Move Generation ====== | ====== Chess - Programming - Move Generation ====== |
| |
<code cpp> | <code> |
// Move bits | // bit | 63| 62| 61| 60| 59| 58| 57| 56| 55| 54| 53| 52| 51| 50| 49| 48| 47| 46| 45| 44| 43| 42| 41| 40| 39| 38| 37| 36| 35| 34| 33| 32| 31| 30| 29| 28| 27| 26| 25| 24| 23| 22| 21| 20| 19| 18| 17| 16| 15| 14| 13| 12| 11| 10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| |
// Higher priority moves have higher ulong value. | // |UGM|VGM|GM |UBM|VBM|BM | |Bm |Nm |Rm |Hm |PV |Km |F |S |M |DC |C |PN |PB |PR |PQ |PRO|CQ |CK |Cm |EP |PC |NC |BC |RC |QC |KC |Ca |QM |DP |P |N |B |R |Q |K |WB |From |To | |
// 6 6 6 6 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 | |
// 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 | // bit 0- 5 : To : Destination square (from 0 to 63). |
// B|CapV |CapA |Promo |Kil|History |C|K|E|D|P|Q|From |To | // bit 6-11 : From : Origin square (from 0 to 63). |
// B = Best Move | // bit 12 : WB : Color doing the move. 0=WHITE 1=BLACK. |
// CapV = Capture Victim | // bit 13 : K : King Move. |
// CapA = Capture Attacker (inverted) | // bit 14 : Q : Queen Move. |
// Promo = Promoted Piece | // bit 15 : R : Rook Move. |
// Kil = Killer Move | // bit 16 : B : Bishop Move. |
// C = Castling | // Bit 17 : N : Knight Move. |
// K = King Move | // Bit 18 : P : Pawn Move. |
// E = En Passant Capture | // Bit 19 : DP : Double Pawn Move. |
// D = Double Pawn Move | // Bit 20 : QM : Quite Move. (Not capture, castling, pawn promotion, or check). |
// P = Pawn Move | // Bit 21 : Ca : Capture. (Including En-Passant Capture). |
// Q = Quiet (not capture, castling, or pawn promotion) | // Bit 22 : KC : King Capture. |
// From = From (needs one extra bit for illegal square) | // Bit 23 : QC : Queen Capture. |
// To = To (needs one extra bit for illegal square) | // Bit 24 : RC : Rook Capture. |
| // Bit 25 : BC : Bishop Capture. |
| // Bit 26 : NC : Knight Capture. |
| // Bit 27 : PC : Pawn Capture. |
| // Bit 28 : EP : En-Passant Capture. |
| // Bit 29 : Cm : Castling Move. |
| // Bit 30 : CK : Castling Move. King Side. |
| // Bit 31 : CQ : Castling Move. Queen Side. |
| // Bit 32 : PRO : Promotion Move. |
| // Bit 33 : PQ : Promotion Move. Queen. |
| // Bit 34 : PR : Promotion Move. Rook. |
| // Bit 35 : PB : Promotion Move. Bishop. |
| // Bit 36 : PN : Promotion Move. Knight. |
| // Bit 37 : C : Checking Move. |
| // Bit 38 : DC : Double Checking Move. |
| // Bit 39 : M : Mating Move. |
| // Bit 40 : S : Stalemating Move. |
| // Bit 41 : F : Forced Move. Only 1 Move possible. |
| // Bit 42 : Km : Killer Move. A quiet move which caused a beta-cutoff in a sibling Cut-node. |
| // Bit 43 : PV : PV Move. Part of the principal variation and therefore a best move found in the previous iteration. |
| // Bit 44 : Hm : Hash Move. A move probed from the transposition table. |
| // Bit 45 : Rm : Refutation Move. A move which fails high at Cut-nodes. |
| // Bit 46 : Nm : Null Move. |
| // Bit 47 : Bm : Book Move. |
| |
| // Bit 58 : BM : Bad Move. ?! When score decreases with 0.50. |
| // Bit 59 : VBM : Very Bad Move. ? when score decreases with 1.00 or more. |
| // Bit 60 : UBM : Ultra Bad Move. ?? - when score decreases with 2.00 or more. |
| // Bit 61 : GM : Good Move. !? When score increases with 0.50. |
| // Bit 62 : VGM : Very Good Move. ! - when score increases with 1.00 or more. |
| // Bit 63 : UGM : Ultra Good Move. !! - when score increases with 2.00 or more. |
</code> | </code> |
| |
---- | ---- |
| |
===== Test Positions ===== | |
| |
<code> | |
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1|1|20 | |
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1|2|400 | |
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1|3|8902 | |
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1|4|197281 | |
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1|5|4865609 | |
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1|6|119060324 | |
8/8/1k6/8/2pP4/8/5BK1/8 b - d3 0 1|6|824064 | |
8/8/1k6/2b5/2pP4/8/5K2/8 b - d3 0 1|6|1440467 | |
8/5k2/8/2Pp4/2B5/1K6/8/8 w - d6 0 1|6|1440467 | |
5k2/8/8/8/8/8/8/4K2R w K - 0 1|6|661072 | |
4k2r/8/8/8/8/8/8/5K2 b k - 0 1|6|661072 | |
3k4/8/8/8/8/8/8/R3K3 w Q - 0 1|6|803711 | |
r3k3/8/8/8/8/8/8/3K4 b q - 0 1|6|803711 | |
r3k2r/1b4bq/8/8/8/8/7B/R3K2R w KQkq - 0 1|4|1274206 | |
r3k2r/7b/8/8/8/8/1B4BQ/R3K2R b KQkq - 0 1|4|1274206 | |
r3k2r/8/3Q4/8/8/5q2/8/R3K2R b KQkq - 0 1|4|1720476 | |
r3k2r/8/5Q2/8/8/3q4/8/R3K2R w KQkq - 0 1|4|1720476 | |
2K2r2/4P3/8/8/8/8/8/3k4 w - - 0 1|6|3821001 | |
3K4/8/8/8/8/8/4p3/2k2R2 b - - 0 1|6|3821001 | |
8/8/1P2K3/8/2n5/1q6/8/5k2 b - - 0 1|5|1004658 | |
5K2/8/1Q6/2N5/8/1p2k3/8/8 w - - 0 1|5|1004658 | |
4k3/1P6/8/8/8/8/K7/8 w - - 0 1|6|217342 | |
8/k7/8/8/8/8/1p6/4K3 b - - 0 1|6|217342 | |
8/P1k5/K7/8/8/8/8/8 w - - 0 1|6|92683 | |
8/8/8/8/8/k7/p1K5/8 b - - 0 1|6|92683 | |
K1k5/8/P7/8/8/8/8/8 w - - 0 1|6|2217 | |
8/8/8/8/8/p7/8/k1K5 b - - 0 1|6|2217 | |
8/k1P5/8/1K6/8/8/8/8 w - - 0 1|7|567584 | |
8/8/8/8/1k6/8/K1p5/8 b - - 0 1|7|567584 | |
8/8/2k5/5q2/5n2/8/5K2/8 b - - 0 1|4|23527 | |
8/5k2/8/5N2/5Q2/2K5/8/8 w - - 0 1|4|23527 | |
r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1|5|193690690 | |
8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1|6|11030083 | |
r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1|5|15833292 | |
rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 1|3|53392 | |
r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 1|5|164075551 | |
8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1|7|178633661 | |
r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1|6|706045033 | |
rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8|5|89941194 | |
1k6/1b6/8/8/7R/8/8/4K2R b K - 0 1|5|1063513 | |
3k4/3p4/8/K1P4r/8/8/8/8 b - - 0 1|6|1134888 | |
8/8/4k3/8/2p5/8/B2P2K1/8 w - - 0 1|6|1015133 | |
</code> | |