Skip to content

Fix time loss in drawn positions#29

Merged
metaember merged 1 commit into
masterfrom
investigate-time-loss
Feb 23, 2026
Merged

Fix time loss in drawn positions#29
metaember merged 1 commit into
masterfrom
investigate-time-loss

Conversation

@metaember

Copy link
Copy Markdown
Owner

Summary

Investigating game 53fzFRX1 where rustchess lost on time from a drawn K+B vs K+B endgame against duchessAI, burning 2+ minutes shuffling its bishop aimlessly.

Three fixes:

  • Fix hard time limit abortshould_stop() was gated by ply % 1024 == 0, so it only checked the clock at ply 0 (root). Once a deep iteration started, the engine couldn't abort mid-search. Removed the gate; should_stop() already throttles internally via a 2048-node counter (~1-3% overhead from two relaxed atomics per node).

  • Pre-search draw detection — Before entering the search, check for insufficient material, 50-move rule, and threefold repetition. If drawn, play any legal move instantly with 0ms time used. Only applies to time-controlled games (not go depth, go movetime, or go infinite).

  • Early termination in iterative deepening — If score is exactly 0 at depth >= 4 and the position has insufficient material, stop deepening immediately. Searching K+B vs K+B to depth 64 can't change the outcome.

Test plan

  • All 362 tests pass
  • Benchmark tracker shows no regression
  • Deploy and observe next drawn endgame on Lichess

…ction

The engine lost on time in game 53fzFRX1 (K+B vs K+B endgame) because:

1. The hard time limit check (should_stop) was gated by `ply % 1024 == 0`,
   meaning it only fired at the root node. Once a deep iteration started,
   the engine couldn't abort mid-search. Fix: remove the ply gate —
   should_stop() already throttles via an internal 2048-node counter.

2. No draw detection before searching. The engine spent its full time
   budget on every move in trivially drawn positions. Fix: check for
   insufficient material, 50-move rule, and threefold repetition before
   entering the search. If drawn, play any legal move instantly.

3. No early termination in iterative deepening for dead draws. Fix: if
   score is 0 at depth >= 4 and position has insufficient material,
   stop deepening immediately.
@metaember metaember merged commit 13881aa into master Feb 23, 2026
@metaember metaember deleted the investigate-time-loss branch February 23, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant