diff options
Diffstat (limited to 'src/board')
-rw-r--r-- | src/board/mod.rs | 12 | ||||
-rw-r--r-- | src/board/zobrist.rs | 4 |
2 files changed, 11 insertions, 5 deletions
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<u64>, + pub positions: Vec<ZobristHash>, // 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<Piece>, previous_ep_target: Option<Square>, 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 + } } diff --git a/src/board/zobrist.rs b/src/board/zobrist.rs index 88a2fb7..251f333 100644 --- a/src/board/zobrist.rs +++ b/src/board/zobrist.rs @@ -11,7 +11,9 @@ const TOTAL_FILES: usize = 8; const TOTAL_CASTLING_RIGHTS: usize = 4; const ZOBRIST_SEED_SIZE: usize = TOTAL_SQUARES * TOTAL_PIECES + TOTAL_CASTLING_RIGHTS + TOTAL_FILES + 1; -pub type ZobristSeed = [u64; ZOBRIST_SEED_SIZE]; +pub type ZobristHash = u64; + +pub type ZobristSeed = [ZobristHash; ZOBRIST_SEED_SIZE]; pub trait Zobrist { fn seed() -> ZobristSeed; |