Add repetition detection

This commit is contained in:
stefiosif
2025-01-19 20:15:23 +02:00
parent 1c7100f510
commit 29d69b5ab1
3 changed files with 40 additions and 0 deletions

View File

@@ -244,6 +244,14 @@ impl Game {
}
}
}
pub fn in_repetition(&self) -> bool {
if self.board.state.halfmove_clock < 4 {
return false;
}
self.history.in_repetition(self.hash)
}
}
impl Default for Game {
@@ -431,4 +439,23 @@ mod tests {
Ok(())
}
#[test]
fn test_in_repetition() -> Result<(), String> {
let mut game = from_fen(FEN)?;
game.make_move(&Move::new(Square::F3, Square::E3));
game.make_move(&Move::new(Square::F7, Square::G7));
game.make_move(&Move::new(Square::E3, Square::F3));
game.make_move(&Move::new(Square::G7, Square::F7));
game.make_move(&Move::new(Square::F3, Square::E3));
assert!(game.in_repetition());
game.make_move(&Move::new(Square::H7, Square::H6));
assert!(!game.in_repetition());
Ok(())
}
}