Add repetition detection
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user