From e743c93f7f5177724dc6f4ae4a2a1d305db80765 Mon Sep 17 00:00:00 2001 From: Adarsh Das Date: Sun, 7 Jun 2026 15:24:56 +0530 Subject: [PATCH] Fix behavior of go infinite where it would return bestmove after MAX_PLY Bench: 3204302 --- src/search.rs | 30 +++++++++++++++++++----------- src/time.rs | 4 ++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/search.rs b/src/search.rs index 984fc3b71..3c8ea7e13 100644 --- a/src/search.rs +++ b/src/search.rs @@ -254,19 +254,21 @@ pub fn start(td: &mut ThreadData, report: Report, thread_count: usize) { nodes * pv_stability * eval_stability * score_trend * best_move_stability }; - if td.time_manager.soft_limit(td, multiplier) { - if !soft_stop_voted { - soft_stop_voted = true; - - let votes = td.shared.soft_stop_votes.fetch_add(1, Ordering::AcqRel) + 1; - let majority = (thread_count * 65).div_ceil(100); - if votes >= majority { - td.shared.status.set(Status::STOPPED); + if td.time_manager.use_time_management() { + if td.time_manager.soft_limit(td, multiplier) { + if !soft_stop_voted { + soft_stop_voted = true; + + let votes = td.shared.soft_stop_votes.fetch_add(1, Ordering::AcqRel) + 1; + let majority = (thread_count * 65).div_ceil(100); + if votes >= majority { + td.shared.status.set(Status::STOPPED); + } } + } else if soft_stop_voted { + soft_stop_voted = false; + td.shared.soft_stop_votes.fetch_sub(1, Ordering::AcqRel); } - } else if soft_stop_voted { - soft_stop_voted = false; - td.shared.soft_stop_votes.fetch_sub(1, Ordering::AcqRel); } if td.shared.status.get() == Status::STOPPED { @@ -274,6 +276,12 @@ pub fn start(td: &mut ThreadData, report: Report, thread_count: usize) { } } + if matches!(td.time_manager.limits(), Limits::Infinite) { + while td.shared.status.get() != Status::STOPPED { + std::hint::spin_loop(); + } + } + if report == Report::Minimal { td.print_uci_info(td.root_depth); } diff --git a/src/time.rs b/src/time.rs index c6eb9f300..e5f8368d5 100644 --- a/src/time.rs +++ b/src/time.rs @@ -91,4 +91,8 @@ impl TimeManager { pub fn limits(&self) -> Limits { self.limits.clone() } + + pub fn use_time_management(&self) -> bool { + matches!(self.limits, Limits::Fischer(..) | Limits::Cyclic(..) | Limits::Time(_)) + } }