Skip to content

Commit

Permalink
Use 3-fold repetition (#206)
Browse files Browse the repository at this point in the history
* threefold?

Bench: 5265026

* typo

Bench: 5265026
  • Loading branch information
cosmobobak authored Oct 12, 2024
1 parent 386b544 commit 39666f7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1599,13 +1599,21 @@ impl Board {

/// Has the current position occurred before in the current game?
pub fn is_repetition(&self) -> bool {
for undo in self.history.iter().rev().skip(1).step_by(2) {
if undo.key == self.key {
return true;
}
// optimisation: if the fifty move counter was zeroed, then any prior positions will not be repetitions.
if undo.fifty_move_counter == 0 {
return false;
let mut counter = 0;
// distance to the last irreversible move
let moves_since_zeroing = self.fifty_move_counter() as usize;
// a repetition is first possible at four ply back:
for (dist_back, u) in self.history.iter().rev().enumerate().take(moves_since_zeroing).skip(3).step_by(2) {
if u.key == self.key {
// in-tree, can twofold:
if dist_back < self.height {
return true;
}
// partially materialised, proper threefold:
counter += 1;
if counter >= 2 {
return true;
}
}
}
false
Expand Down

0 comments on commit 39666f7

Please sign in to comment.