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/search.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/grossmeister/search.rs') 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 -- cgit v1.2.3