diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bot.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/bot.cpp b/src/bot.cpp index 4682998..ef6f647 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -307,6 +307,15 @@ Move GetBestMove(Game *b, int maxDepth, move_options options) { while (continueSearching) { SearchResult result = SearchDepth(b, depth, &bestMove); + + // If the clock expired inside this iteration, the returned score/move may + // come from a partially searched tree. Keep the last fully completed + // iteration instead of reporting INF as a fake mate or playing a random + // first move. + if (searchStopped) { + break; + } + bestMove = result.bestMove; auto now = std::chrono::steady_clock::now(); @@ -335,9 +344,6 @@ Move GetBestMove(Game *b, int maxDepth, move_options options) { if (elapsedSeconds >= MAXIMUM_TIME_PER_MOVE && usingDefaultDepth) { continueSearching = false; } - if (searchStopped) { - continueSearching = false; - } } return bestMove; |
