aboutsummaryrefslogtreecommitdiff
path: root/src/board/mod.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-09-03 17:32:31 +0300
committereug-vs <eugene@eug-vs.xyz>2023-09-03 18:23:52 +0300
commit9927af55dd12bc5eca7ff17e9dbc2665c42fcfb7 (patch)
treebfbb33376f8d9ba84de21d626e6fb8dda4d1471a /src/board/mod.rs
parent81b0addcc9d5ff2b428981ca88ee0acdec4db2a9 (diff)
downloadchessnost-9927af55dd12bc5eca7ff17e9dbc2665c42fcfb7.tar.gz
refactor: separate threefold_repetitionHEADmaster
Diffstat (limited to 'src/board/mod.rs')
-rw-r--r--src/board/mod.rs12
1 files changed, 8 insertions, 4 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
+ }
}