Skip to content

Commit 35a4ecf

Browse files
authored
Fix fullmove counter handling in move application (#1035)
The move counter previously was being increased on the wrong moves. Before: Fen 1: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 Move 1: position startpos moves e2e4 Fen 2: rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 2 (Wrong) After: Fen 1: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 Move 1: position startpos moves e2e4 Fen 2: rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1 (Correct) STC Elo | 1.60 +- 2.11 (95%) SPRT | 8.0+0.08s Threads=1 Hash=16MB LLR | 2.95 (-2.25, 2.89) [-2.75, 0.25] Games | N: 27206 W: 7005 L: 6880 D: 13321 Penta | [115, 3031, 7195, 3138, 124] https://recklesschess.space/test/14826/ Bench: 2847081
1 parent d20f8c6 commit 35a4ecf

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/board.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ impl Board {
199199
self.fullmove_number += self.side_to_move() as usize;
200200
}
201201

202+
pub const fn retreat_fullmove_counter(&mut self) {
203+
self.fullmove_number -= self.side_to_move() as usize;
204+
}
205+
202206
pub const fn set_frc(&mut self, frc: bool) {
203207
self.frc = frc;
204208
}

src/board/makemove.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl Board {
116116
_ => (),
117117
}
118118

119+
self.advance_fullmove_counter();
119120
self.side_to_move = !self.side_to_move;
120121

121122
self.state.castling.raw &= self.castling_rights[from] & self.castling_rights[to];
@@ -149,6 +150,7 @@ impl Board {
149150

150151
pub fn undo_move(&mut self, mv: Move) {
151152
self.side_to_move = !self.side_to_move;
153+
self.retreat_fullmove_counter();
152154

153155
let from = mv.from();
154156
let to = mv.to();

src/uci.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ fn make_uci_move(board: &mut Board, uci_move: &str) {
277277
let moves = board.generate_all_moves();
278278
if let Some(mv) = moves.iter().map(|entry| entry.mv).find(|mv| mv.to_uci(board) == uci_move) {
279279
board.make_move(mv, &mut NullBoardObserver);
280-
board.advance_fullmove_counter();
281280
}
282281
}
283282

0 commit comments

Comments
 (0)