From 299c6d6dee96a50f9366955192f922d449d11f20 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Mon, 22 Jan 2024 01:30:47 +0100 Subject: feat: store PV in a separate table --- src/grossmeister/search.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/grossmeister/search.rs') diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs index c81c586..372fecc 100644 --- a/src/grossmeister/search.rs +++ b/src/grossmeister/search.rs @@ -47,6 +47,12 @@ impl Grossmeister { return 0.0 } + // Mate distance pruning + let mating_score = Grossmeister::MDP(&mut alpha, &mut beta, root_distance); + if mating_score != 0.0 { + return mating_score + } + if let Some(transposition) = self.transposition() { if transposition.depth >= depth_left { match transposition.node_type { @@ -77,12 +83,6 @@ impl Grossmeister { node_type: NodeType::All, }; - // Mate distance pruning - let mating_score = Grossmeister::MDP(&mut alpha, &mut beta, root_distance); - if mating_score != 0.0 { - return mating_score - } - if depth_left == 0 { return self.quiscence(alpha, beta, root_distance) } @@ -167,6 +167,12 @@ impl Grossmeister { return 0.0 } + // Mate distance pruning + let mating_score = Grossmeister::MDP(&mut alpha, &mut beta, root_distance); + if mating_score != 0.0 { + return mating_score + } + if let Some(transposition) = self.transposition() { match transposition.node_type { NodeType::PV => { @@ -195,14 +201,6 @@ impl Grossmeister { node_type: NodeType::All, }; - // Mate distance pruning - let mating_score = Grossmeister::MDP(&mut alpha, &mut beta, root_distance); - if mating_score != 0.0 { - transposition.score = mating_score; - return mating_score - } - - let mut tactical_only = false; if !self.board.is_king_in_check(color) { // If we are not in check, we can evaluate stand pat @@ -263,17 +261,17 @@ impl Grossmeister { alpha } - fn reconstruct_pv(&mut self, depth: u8) -> Vec { + fn collect_pv(&mut self, depth: u8) -> Vec { let mut pv = Vec::with_capacity(depth as usize); if depth > 0 { - if let Some(transposition) = self.transposition().cloned() { + if let Some(transposition) = self.pv().cloned() { if let Some(mov) = transposition.mov { if transposition.depth < depth { - println!("info string found lower-depth {:?}-node ({}) than expected ({}). Probably bad", transposition.node_type, transposition.depth, depth); + println!("info string found lower-depth {:?} node ({}) than expected ({}). Probably bad", transposition.node_type, transposition.depth, depth); } if transposition.depth > depth { - println!("info string found higher-depth {:?}-node ({}) than expected ({}). Good for us?", transposition.node_type, transposition.depth, depth); + println!("info string found higher-depth {:?} node ({}) than expected ({}). Good for us?", transposition.node_type, transposition.depth, depth); } let ep_target_before = self.board.ep_target; let castling_rights_before = self.board.castling_rights; @@ -281,12 +279,14 @@ impl Grossmeister { let captured = self.board.make_move(mov); pv.push(mov); - let mut subtree_pv = self.reconstruct_pv(transposition.depth - 1); + let mut subtree_pv = self.collect_pv(depth - 1); pv.append(&mut subtree_pv); self.board.unmake_move(mov, captured, ep_target_before, castling_rights_before, hash_before); } + } else { + println!("No PV node found for hash {}", self.board.hash); } } @@ -336,7 +336,7 @@ impl Grossmeister { } best_score = score; - pv = self.reconstruct_pv(depth); + pv = self.collect_pv(depth); // Print UCI info print!("info depth {} score ", depth); -- cgit v1.2.3