Fix time loss in drawn positions#29
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 abort —
should_stop()was gated byply % 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, orgo 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