From 2f7a449038fb5dbc620e9f156c24bb6fa318d8fb Mon Sep 17 00:00:00 2001 From: eug-vs Date: Mon, 4 Sep 2023 10:23:56 +0300 Subject: feat: define strict ordering between ttable items --- src/grossmeister/search.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/grossmeister/search.rs') diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs index d0fddbb..23bcdfa 100644 --- a/src/grossmeister/search.rs +++ b/src/grossmeister/search.rs @@ -96,7 +96,6 @@ impl Grossmeister { } else { // After we have PV-node (that raised alpha) all other nodes will be searched // with zero-window first to confirm this assumption - // TODO: changing 0.001 -> 0.0001 leads to a weird bug let score = self.negamax_search(-(alpha + 0.001), -alpha, depth_left - 1, root_distance + 1); // In case some of the other nodes raises alpha, then it's true PV node now, // let's research with full window to find its exact value @@ -110,10 +109,10 @@ impl Grossmeister { self.board.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before); if score >= beta { - self.transposition_table[(self.board.hash % TTABLE_SIZE) as usize] = Some(TranspositionTableItem { + self.store_transposition(TranspositionTableItem { hash: self.board.hash, mov, - depth: depth_left, // TODO: should be actual depth searched + depth: depth_left, node_type: NodeType::Cut, score, }); @@ -128,18 +127,18 @@ impl Grossmeister { alpha = score; should_pv_search = false; // Once we have PV-node we can start zero-window searching - self.transposition_table[(self.board.hash % TTABLE_SIZE) as usize] = Some(TranspositionTableItem { + self.store_transposition(TranspositionTableItem { hash: self.board.hash, mov, - depth: depth_left, // TODO: should be actual depth searched + depth: depth_left, node_type: NodeType::PV, score, }); - } else if self.transposition().is_none() { - self.transposition_table[(self.board.hash % TTABLE_SIZE) as usize] = Some(TranspositionTableItem { + } else { + self.store_transposition(TranspositionTableItem { hash: self.board.hash, mov, - depth: depth_left, // TODO: should be actual depth searched + depth: depth_left, node_type: NodeType::All, score, }); @@ -230,6 +229,7 @@ impl Grossmeister { let mut pv = Vec::with_capacity(depth as usize); if let Some(transposition) = self.transposition() { + debug_assert!(transposition.node_type == NodeType::PV); let mov = transposition.mov; let ep_target_before = self.board.ep_target; let castling_rights_before = self.board.castling_rights; -- cgit v1.2.3