From 32100cca965309245fe2badbe20a29a6f2c99220 Mon Sep 17 00:00:00 2001 From: Paul Tsouchlos Date: Sun, 9 Nov 2025 12:00:07 -0500 Subject: [PATCH 1/2] chore: centralize where LMR vars are initialized Initialize the LMR related vars earlier in the move loop so we can re-use them for other pruning techniques. bench: 1091922 --- engine/src/search.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/engine/src/search.rs b/engine/src/search.rs index e5c7fef..99908df 100644 --- a/engine/src/search.rs +++ b/engine/src/search.rs @@ -453,17 +453,22 @@ impl<'a, Log: LogLevel> Search<'a, Log> { // sort moves by MVV/LVA let move_iter = InplaceIncrementalSort::new(move_list.as_mut_slice(), &mut order_list); - // initialize best move and best score - // we ensured we have moves earlier - // let mut best_move = Some(*sorted_moves[0]); - - // really "bad" initial score + // Really "bad" initial score let mut best_score = -Score::INF; let mut best_move = tt_move; - let lmr_reduction = 1; - // loop through all moves + // Loop through all moves for (i, mv) in move_iter.into_iter().enumerate() { + // Calculate the LMR reduction and depth which will be used later in FP + let lmr_table_value = self.lmr_table.at(depth as usize, i); + let base_reduction = if let Some(table_val) = lmr_table_value { + *table_val + } else { + 1f64 + }; + let lmr_reduction = (1f64 + base_reduction).floor() as i16; + let _lmr_depth = depth.saturating_sub(lmr_reduction); + // Move-loop pruning techniques // LMP - Late Move Pruning @@ -491,9 +496,7 @@ impl<'a, Log: LogLevel> Search<'a, Log> { -self.negamax::(board, depth - 1, ply + 1, -beta, -alpha_use, &mut local_pv) } else { let reduction = if mv.is_quiet() && depth >= 3 && board.full_move_number() >= 3 { - let lmr_table_val = self.lmr_table.at(depth as usize, i); - assert!(lmr_table_val.is_some(), "LMR table not initialized."); - (lmr_reduction as f64 + lmr_table_val.unwrap()).floor() as i16 + lmr_reduction } else { 1 }; From 24f5180645e85d325d0727cddf18c5b2ccc5cfab Mon Sep 17 00:00:00 2001 From: Paul Tsouchlos Date: Sun, 9 Nov 2025 12:03:02 -0500 Subject: [PATCH 2/2] chore: centralize more vars bench: 1091922 --- engine/src/search.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/engine/src/search.rs b/engine/src/search.rs index 99908df..9254dda 100644 --- a/engine/src/search.rs +++ b/engine/src/search.rs @@ -468,6 +468,9 @@ impl<'a, Log: LogLevel> Search<'a, Log> { }; let lmr_reduction = (1f64 + base_reduction).floor() as i16; let _lmr_depth = depth.saturating_sub(lmr_reduction); + let is_in_check = board.is_in_check(&self.move_gen); + let is_root = Node::ROOT; + let is_pv = Node::PV; // Move-loop pruning techniques @@ -475,8 +478,7 @@ impl<'a, Log: LogLevel> Search<'a, Log> { // We assume our move ordering is just too good, so if we're under a certain depth // and have made more than a certain number of moves, we can assume that later moves // won't be as good, so we prune them. - if !Node::ROOT && !Node::PV && !board.is_in_check(&self.move_gen) && !best_score.mated() - { + if !is_root && !is_pv && !is_in_check && !best_score.mated() { let min_lmp_moves = LMP_MIN_THRESHOLD_DEPTH as usize + depth as usize * depth as usize; if i >= min_lmp_moves {