Skip to content

Commit 0be6cd4

Browse files
authored
Fix non-canonical hash after null moves (#1095)
increment_stack toggles the castling key out on every ply, which is the remove-old-rights half of the pair that make_move completes when it updates castling rights. make_null_move goes through increment_stack but never toggles it back, so the hash after a null move is left off by the castling term: a position reached via a null move hashes differently from the same position parsed from FEN. Move the castling toggle out of the shared increment_stack into make_move, which owns both halves. Null moves now leave castling untouched, matching the standard convention (Stockfish, Viridithas). STC Elo | 3.45 +- 2.88 (95%) SPRT | 8.0+0.08s Threads=1 Hash=16MB LLR | 2.92 (-2.25, 2.89) [-2.75, 0.25] Games | N: 14716 W: 3733 L: 3587 D: 7396 Penta | [43, 1679, 3779, 1803, 54] https://recklesschess.space/test/15402/ LTC Elo | 2.57 +- 2.47 (95%) SPRT | 40.0+0.40s Threads=1 Hash=64MB LLR | 2.91 (-2.25, 2.89) [-2.75, 0.25] Games | N: 17832 W: 4442 L: 4310 D: 9080 Penta | [7, 2002, 4764, 2138, 5] https://recklesschess.space/test/15403/ Bench: 2931707
1 parent 22d7558 commit 0be6cd4

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/board/makemove.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ impl Board {
66
self.halfmove_number += 1;
77
self.state_stack.push(self.state);
88
self.state.keys.toggle_side();
9-
self.state.keys.toggle_castling(self.state.castling);
109
self.state.repetition = 0;
1110

1211
if self.en_passant() != Square::None {
@@ -94,6 +93,7 @@ impl Board {
9493
self.state.material += promotion.value() - PieceType::Pawn.value();
9594
}
9695

96+
self.state.keys.toggle_castling(self.state.castling);
9797
self.state.castling.raw &= self.castling_rights[from] & self.castling_rights[to];
9898
self.state.keys.toggle_castling(self.state.castling);
9999

0 commit comments

Comments
 (0)