Skip to content

Commit 7dd6b0f

Browse files
authored
Fix behavior of go infinite where it would return bestmove after MAX_PLY (#1075)
Bench: 3204302
1 parent f9390b4 commit 7dd6b0f

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/search.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,26 +254,34 @@ pub fn start(td: &mut ThreadData, report: Report, thread_count: usize) {
254254
nodes * pv_stability * eval_stability * score_trend * best_move_stability
255255
};
256256

257-
if td.time_manager.soft_limit(td, multiplier) {
258-
if !soft_stop_voted {
259-
soft_stop_voted = true;
260-
261-
let votes = td.shared.soft_stop_votes.fetch_add(1, Ordering::AcqRel) + 1;
262-
let majority = (thread_count * 65).div_ceil(100);
263-
if votes >= majority {
264-
td.shared.status.set(Status::STOPPED);
257+
if td.time_manager.use_time_management() {
258+
if td.time_manager.soft_limit(td, multiplier) {
259+
if !soft_stop_voted {
260+
soft_stop_voted = true;
261+
262+
let votes = td.shared.soft_stop_votes.fetch_add(1, Ordering::AcqRel) + 1;
263+
let majority = (thread_count * 65).div_ceil(100);
264+
if votes >= majority {
265+
td.shared.status.set(Status::STOPPED);
266+
}
265267
}
268+
} else if soft_stop_voted {
269+
soft_stop_voted = false;
270+
td.shared.soft_stop_votes.fetch_sub(1, Ordering::AcqRel);
266271
}
267-
} else if soft_stop_voted {
268-
soft_stop_voted = false;
269-
td.shared.soft_stop_votes.fetch_sub(1, Ordering::AcqRel);
270272
}
271273

272274
if td.shared.status.get() == Status::STOPPED {
273275
break;
274276
}
275277
}
276278

279+
if matches!(td.time_manager.limits(), Limits::Infinite) {
280+
while td.shared.status.get() != Status::STOPPED {
281+
std::hint::spin_loop();
282+
}
283+
}
284+
277285
if report == Report::Minimal {
278286
td.print_uci_info(td.root_depth);
279287
}

src/time.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ impl TimeManager {
9191
pub fn limits(&self) -> Limits {
9292
self.limits.clone()
9393
}
94+
95+
pub fn use_time_management(&self) -> bool {
96+
matches!(self.limits, Limits::Fischer(..) | Limits::Cyclic(..) | Limits::Time(_))
97+
}
9498
}

0 commit comments

Comments
 (0)