feat: hard time limit for moves still open at the soft limit

With smart pruning most searches stop early and the clock piles up:
after move 40 of 8+0.08 self-play about 5 s of the 8 s were left. A
diagnostic of 202 searches showed 190 settled early; the 12 that reached
the time limit were the open ones (the best move had a median 50% of the
root visits, and was the best by Q in only 3 of 12).

So reaching the soft limit (the old allocation) is itself the sign of an
open move. Under a game clock such a search now runs on, with smart
pruning measured against a hard limit of min(3 x soft, remaining / 3),
until it settles or reaches that limit. movetime, nodes and infinite are
unchanged (their hard limit is the soft one).

Self-play diagnostic at 8+0.08 (3 games, 80 plies), main -> this:
average time per move 152-156 -> 162-189 ms, longest move about 350 ->
860-1040 ms, clock left after move 40 4.8-5.4 -> 2.4-5.0 s. go movetime
500 still stops at 480 ms; a 300 ms clock uses 6 ms.

The bench is unchanged: it searches by playout count.

Bench: 554375

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rektdieandclaude committed 2026-11-15 16:01:27 +01:00
1 parent ca921ce2e2
commit bf62fe185f
2 files changed
+18 -8

No files matched your search

+14 -6
View File
@@ -137,11 +137,12 @@ i64 Searcher::elapsed_ms() const {
void Searcher::compute_time_limit(const SearchLimits& limits) {
time_limit_ms_ = 0;
hard_limit_ms_ = 0;
clock_search_ = false;
if (limits.infinite) return;
if (limits.movetime) {
time_limit_ms_ = std::max<i64>(1, limits.movetime - params.move_overhead);
time_limit_ms_ = hard_limit_ms_ = std::max<i64>(1, limits.movetime - params.move_overhead);
return;
}
@@ -152,10 +153,12 @@ void Searcher::compute_time_limit(const SearchLimits& limits) {
const i64 moves_left = limits.movestogo ? std::min(limits.movestogo, 40) : 25;
const i64 target = remaining / moves_left + limits.inc[us] * 3 / 4;
time_limit_ms_ = std::clamp<i64>(target, 1, remaining / 2 + 1);
// A move that is still open at the soft limit may run on up to this.
hard_limit_ms_ = std::max(time_limit_ms_, std::min(time_limit_ms_ * HARD_LIMIT_FACTOR, remaining / 3));
clock_search_ = true;
}
bool Searcher::best_move_settled(i64 ms) const {
bool Searcher::best_move_settled(i64 ms, i64 limit_ms) const {
// Smart pruning (Lc0): stop when no other root move can catch up with the
// leading one in the playouts the remaining time still allows, at the
// speed so far, scaled down by SMART_PRUNING_FACTOR. Only the visits of
@@ -178,7 +181,7 @@ bool Searcher::best_move_settled(i64 ms) const {
}
if (leader != best_child(Tree::root())) return false;
const double remaining =
double(iterations_) / double(ms) * double(time_limit_ms_ - ms) / SMART_PRUNING_FACTOR;
double(iterations_) / double(ms) * double(limit_ms - ms) / SMART_PRUNING_FACTOR;
return double(second) + remaining < double(first);
}
@@ -194,9 +197,14 @@ bool Searcher::should_stop(const SearchLimits& limits) const {
// The clock is cheap but not free; look at it every 64 playouts.
if (time_limit_ms_ && (iterations_ & 63) == 0) {
const i64 ms = elapsed_ms();
if (ms >= time_limit_ms_) return true;
// Under a game clock the time saved on a settled move goes to later moves.
if (clock_search_ && best_move_settled(ms)) return true;
if (ms >= hard_limit_ms_) return true;
// Under a game clock the time saved on a settled move goes to later
// moves. A move that is not settled by the soft limit (time_limit_ms_)
// is an open one: it searches on until it settles against the hard
// limit or reaches it. Other limits stop at the soft limit, which is
// also their hard one.
const bool extended = ms >= time_limit_ms_;
if (clock_search_ && best_move_settled(ms, extended ? hard_limit_ms_ : time_limit_ms_)) return true;
}
return false;
}