From 9d8304d35d5f9e8f9e70f231971b064e9e22ad68 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Mon, 4 Sep 2023 14:25:05 +0300 Subject: fix: dont put scores outside of bounds in table --- src/grossmeister/move_selector.rs | 8 ++++++-- src/grossmeister/search.rs | 29 +++++++++++++++-------------- src/grossmeister/ttable.rs | 2 +- 3 files changed, 22 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/grossmeister/move_selector.rs b/src/grossmeister/move_selector.rs index 33f836b..c55051e 100644 --- a/src/grossmeister/move_selector.rs +++ b/src/grossmeister/move_selector.rs @@ -2,7 +2,7 @@ use smallvec::SmallVec; use crate::{moves::Move, board::{Board, move_generation::MoveList}}; -use super::Grossmeister; +use super::{Grossmeister, ttable::NodeType}; pub type ScoredMove = (Move, f32); pub type ScoredMoveList = SmallVec<[ScoredMove; 128]>; @@ -165,7 +165,11 @@ impl Grossmeister { MoveGenStage::Hash => { self.next_stage(); if let Some(transposition) = self.transposition() { - return Some(transposition.mov); + if transposition.node_type != NodeType::All { + if let Some(mov) = transposition.mov { + return Some(mov) + } + } } } MoveGenStage::WinningOrEqualTactical => { diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs index d5d6b30..15cae3a 100644 --- a/src/grossmeister/search.rs +++ b/src/grossmeister/search.rs @@ -111,10 +111,10 @@ impl Grossmeister { if score >= beta { self.store_transposition(TranspositionTableItem { hash: self.board.hash, - mov, + mov: Some(mov), depth: depth_left, node_type: NodeType::Cut, - score, + score: beta, }); if mov.kind == MoveKind::Quiet { @@ -129,7 +129,7 @@ impl Grossmeister { self.store_transposition(TranspositionTableItem { hash: self.board.hash, - mov, + mov: Some(mov), depth: depth_left, node_type: NodeType::PV, score, @@ -137,10 +137,10 @@ impl Grossmeister { } else { self.store_transposition(TranspositionTableItem { hash: self.board.hash, - mov, + mov: None, depth: depth_left, node_type: NodeType::All, - score, + score: alpha, }); } } else { @@ -229,17 +229,18 @@ impl Grossmeister { let mut pv = Vec::with_capacity(depth as usize); if let Some(transposition) = self.transposition() { - let mov = transposition.mov; - let ep_target_before = self.board.ep_target; - let castling_rights_before = self.board.castling_rights; - let hash_before = self.board.hash; - let captured = self.board.make_move(mov); + if let Some(mov) = transposition.mov { + let ep_target_before = self.board.ep_target; + let castling_rights_before = self.board.castling_rights; + let hash_before = self.board.hash; + let captured = self.board.make_move(mov); - let mut subtree_pv = self.reconstruct_pv(depth - 1); - self.board.unmake_move(mov, captured, ep_target_before, castling_rights_before, hash_before); + let mut subtree_pv = self.reconstruct_pv(depth - 1); + self.board.unmake_move(mov, captured, ep_target_before, castling_rights_before, hash_before); - pv.push(mov); - pv.append(&mut subtree_pv); + pv.push(mov); + pv.append(&mut subtree_pv); + } } debug_assert!(pv.len() == depth as usize); pv diff --git a/src/grossmeister/ttable.rs b/src/grossmeister/ttable.rs index 8838093..bb151b3 100644 --- a/src/grossmeister/ttable.rs +++ b/src/grossmeister/ttable.rs @@ -34,7 +34,7 @@ impl PartialOrd for NodeType { pub struct TranspositionTableItem { /// Zobrist hash of this position pub hash: u64, - pub mov: Move, + pub mov: Option, pub depth: u8, pub score: f32, pub node_type: NodeType, -- cgit v1.2.3