pub struct History { /* private fields */ }Expand description
History primary use is for tracking repeated moves to prevent threefold repetition. It is stateful, in that functions assume the next interaction comes from the next possible move in a played game.
It contains the hashes of all previously visited positions, and the indices of positions which cannot be repeated in future positions.
Implementations§
Source§impl History
impl History
Sourcepub fn new(game: &Game, ztable: &ZobristTable) -> Self
pub fn new(game: &Game, ztable: &ZobristTable) -> Self
Create a new History from a game and a Zobrist Table.
Sourcepub fn push(&mut self, hash: HashKind, is_unrepeatable: bool)
pub fn push(&mut self, hash: HashKind, is_unrepeatable: bool)
Pushes a new position into the hash history, and updates the most recent unrepeatable index if applicable.
Sourcepub fn pop(&mut self)
pub fn pop(&mut self)
Pops a position from history stack. If the popped item was the most recent unrepeatable, then replace it with the previous unrepeatable index.
Sourcepub fn contains(&self, hash: HashKind) -> bool
pub fn contains(&self, hash: HashKind) -> bool
Returns true if the position occurs at least once in history. This is done by only checking the history from the last unrepeatable index to the most recent entry. All positions before the index cannot reoccur in the next sequence.
Sourcepub fn contains_n(&self, hash: HashKind, count: usize) -> bool
pub fn contains_n(&self, hash: HashKind, count: usize) -> bool
Returns true if the position occurs in history at least n times,
assuming the position to check may be the next move in this game’s history.
Sourcepub fn is_threefold_repetition(&self, hash: HashKind) -> bool
pub fn is_threefold_repetition(&self, hash: HashKind) -> bool
Returns true if the position occurs twice in history, indicating that the given position is the second repetition (position occurs total of three times).
Sourcepub fn is_twofold_repetition(&self, hash: HashKind) -> bool
pub fn is_twofold_repetition(&self, hash: HashKind) -> bool
Returns true if the position occurs once in history, indicating that the given position is the first repetition (position occurs total of two times).