Skip to content

Commit

Permalink
Fix endless search with soft nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tearth committed Nov 23, 2024
1 parent 072c98a commit 8e5cb76
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/engine/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct SearchContext {
pub current_depth: i8,
pub forced_depth: i8,
pub max_nodes_count: u64,
pub max_soft_nodes_count: u64,
pub max_move_time: u32,
pub moves_to_go: u32,
pub moves_to_search: Vec<Move>,
Expand Down Expand Up @@ -81,6 +82,7 @@ impl SearchContext {
current_depth: 1,
forced_depth: 0,
max_nodes_count: 0,
max_soft_nodes_count: 0,
max_move_time: 0,
moves_to_go: 0,
moves_to_search: Vec::new(),
Expand Down Expand Up @@ -163,7 +165,7 @@ impl Iterator for SearchContext {
}

// With soft nodes enabled, search is stopped after completing the depth instead aborting it in the middle
if self.soft_nodes && self.max_nodes_count > 0 && self.stats.nodes_count >= self.max_nodes_count {
if self.soft_nodes && self.max_soft_nodes_count > 0 && self.stats.nodes_count + self.stats.q_nodes_count >= self.max_soft_nodes_count {
return None;
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/search/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn run_internal<const ROOT: bool, const PV: bool>(
}
}

if !context.soft_nodes && context.max_nodes_count != 0 {
if context.max_nodes_count != 0 {
if context.stats.nodes_count + context.stats.q_nodes_count >= context.max_nodes_count {
context.abort_flag.store(true, Ordering::Relaxed);
return INVALID_SCORE;
Expand Down
13 changes: 8 additions & 5 deletions src/interface/uci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,12 @@ pub fn run() {
options_lock.insert("SyzygyProbeLimit".to_string(), UciOption::new(5, "spin", 1, 9, 8));
options_lock.insert("SyzygyProbeDepth".to_string(), UciOption::new(6, "spin", 1, 32, 6));
options_lock.insert("Ponder".to_string(), UciOption::new(7, "check", false, false, false));
options_lock.insert("Soft Nodes".to_string(), UciOption::new(50, "check", false, false, false));
options_lock.insert("Search Noise".to_string(), UciOption::new(50, "check", false, false, false));
options_lock.insert("Clear Hash".to_string(), UciOption::new(8, "button", "", "", ""));

#[cfg(feature = "dev")]
{
options_lock.insert("Soft Nodes".to_string(), UciOption::new(50, "check", false, false, false));
options_lock.insert("Search Noise".to_string(), UciOption::new(50, "check", false, false, false));
options_lock.insert("Crash Files".to_string(), UciOption::new(50, "check", false, false, false));
}
options_lock.insert("Crash Files".to_string(), UciOption::new(50, "check", false, false, false));

#[cfg(feature = "dev")]
{
Expand Down Expand Up @@ -449,6 +447,7 @@ fn handle_go(params: &[String], state: &UciState) {
context_lock.current_depth = 1;
context_lock.forced_depth = forced_depth;
context_lock.max_nodes_count = max_nodes_count;
context_lock.max_soft_nodes_count = max_nodes_count;
context_lock.max_move_time = max_move_time;
context_lock.moves_to_go = moves_to_go;
context_lock.moves_to_search = moves_to_search.clone();
Expand All @@ -464,6 +463,10 @@ fn handle_go(params: &[String], state: &UciState) {
context_lock.syzygy_probe_depth = syzygy_probe_depth;
context_lock.stats = SearchStats::default();

if soft_nodes {
context_lock.max_nodes_count *= 10;
}

context_lock.lines.clear();
context_lock.helper_contexts.write().unwrap().clear();

Expand Down

0 comments on commit 8e5cb76

Please sign in to comment.