From 9927af55dd12bc5eca7ff17e9dbc2665c42fcfb7 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 3 Sep 2023 17:32:31 +0300 Subject: refactor: separate threefold_repetition --- src/board/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/board/mod.rs') diff --git a/src/board/mod.rs b/src/board/mod.rs index 39248eb..1e4fd93 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -1,6 +1,6 @@ use crate::{bitboard::{Bitboard, BitboardFns}, moves::{Move, MoveKind}, attacks::Attacks, square::Square, board::io::IO, clock::Clock}; -use self::{zobrist::{ZobristSeed, Zobrist}, piece::Piece, color::Color}; +use self::{zobrist::{ZobristSeed, Zobrist, ZobristHash}, piece::Piece, color::Color}; pub mod io; pub mod color; pub mod piece; @@ -27,12 +27,12 @@ pub struct Board { pub clock: Clock, /// List of all positions to determine repetitions - pub positions: Vec, + pub positions: Vec, // Computed values pub occupancy: Bitboard, /// Zobrist hash of the current position - pub hash: u64, + pub hash: ZobristHash, zobrist_seed: ZobristSeed, @@ -256,7 +256,7 @@ impl Board { captured_piece: Option, previous_ep_target: Option, previous_castling_rights: [[bool; 2]; 2], - previous_hash: u64, + previous_hash: ZobristHash, ) { let move_source_bb = mov.source.to_bitboard(); let move_target_bb = mov.target.to_bitboard(); @@ -388,6 +388,10 @@ impl Board { let square = king_bb.bitscan(); self.is_square_attacked(square, color.flip()) } + + pub fn threefold_repetition(&self) -> bool { + self.positions.iter().filter(|&&p| p == self.hash).count() >= 3 + } } -- cgit v1.2.3