From d3f2b75ed51b3d19d4b68998cd3ef29400bd34db Mon Sep 17 00:00:00 2001 From: Paul Tsouchlos Date: Sun, 12 Jul 2026 16:46:34 -0400 Subject: [PATCH] chore: fallback for improvement calc Fallback to ply - 4 when not in check and and the ply - 2 static eval was not valid. bench: 1173913 --- crates/engine/src/search.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/search.rs b/crates/engine/src/search.rs index 6b0e0219..b5905cc5 100644 --- a/crates/engine/src/search.rs +++ b/crates/engine/src/search.rs @@ -89,9 +89,15 @@ impl Display for SearchResult { /// Helper to calculate the improvement of the static evaluation from our previous move. fn calculate_improvement(td: &ThreadData, ply: i16, static_eval: Score, in_check: bool) -> i32 { + if in_check { + return 0; + } + let ply_idx = ply as usize; - if ply >= 2 && score::is_valid(td.stack[ply_idx - 2].static_eval) && !in_check { + if ply >= 2 && score::is_valid(td.stack[ply_idx - 2].static_eval) { (static_eval.0 as i32) - td.stack[ply_idx - 2].static_eval + } else if ply >= 4 && score::is_valid(td.stack[ply_idx - 4].static_eval) { + (static_eval.0 as i32) - td.stack[ply_idx - 4].static_eval } else { 0 }