aboutsummaryrefslogtreecommitdiff
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
parent81b0addcc9d5ff2b428981ca88ee0acdec4db2a9 (diff)
downloadchessnost-master.tar.gz
refactor: separate threefold_repetitionHEADmaster
-rw-r--r--src/board/mod.rs12
-rw-r--r--src/board/zobrist.rs4
-rw-r--r--src/grossmeister/search.rs8
3 files changed, 14 insertions, 10 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;
diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs
index fb7e385..2d20e3a 100644
--- a/src/grossmeister/search.rs
+++ b/src/grossmeister/search.rs
@@ -44,8 +44,7 @@ impl Grossmeister {
let mut principal_variation = Vec::new();
let color = self.board.color();
- if self.board.positions.iter().filter(|p| **p == self.board.hash).count() >= 3 {
- // Draw by repetition
+ if self.board.threefold_repetition() {
return (0.0, principal_variation);
}
@@ -176,9 +175,8 @@ impl Grossmeister {
pub fn quiscence(&mut self, mut alpha: f32, mut beta: f32, root_distance: u8) -> f32 {
let color = self.board.color();
- if self.board.positions.iter().filter(|p| **p == self.board.hash).count() >= 3 {
- // Draw by repetition
- return 0.0;
+ if self.board.threefold_repetition() {
+ return 0.0
}
// Mate distance pruning