From ac99b1562391201b954c3b9dbd3c81a3050197a4 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 24 Aug 2026 17:06:42 +0200 Subject: feat(search): removing double clock check and instalny finish search with only one legal moves --- src/bot.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/bot.cpp b/src/bot.cpp index 8fe491e..7168f85 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -337,22 +338,23 @@ uint16_t GetBestMove(Game *b, int maxDepth, move_options options) { // use depth INF if caller hasnt provided depth int actualDepth = maxDepth > 0 ? maxDepth : INF; - bool hasSetSpecialTimeLimit = false; - auto legalMoves = GetSortedLegalMoves(b, ALL, nullptr); if (legalMoves.empty()) { assert(false && "GetBestMove called with no legal moves"); return {}; } + // if there is only one legal moves play that without doing anything else + if (legalMoves.size() == 1) { + return legalMoves[0]; + } uint16_t bestMove = legalMoves[0]; searchStartTime = std::chrono::steady_clock::now(); - timeToThingMS = DEFAULT_TIME * 1000; // to big number to ever achiave + timeToThingMS = DEFAULT_TIME * 1000; if (options.wtime != -1 && options.btime != -1) { - hasSetSpecialTimeLimit = true; int increment = b->turn ? options.wncr : options.bncr; double time_remaning = b->turn ? options.wtime : options.btime; @@ -365,10 +367,6 @@ uint16_t 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; } @@ -400,13 +398,6 @@ uint16_t GetBestMove(Game *b, int maxDepth, move_options options) { if (depth > actualDepth) { continueSearching = false; } - double elapsedSeconds = - std::chrono::duration(std::chrono::steady_clock::now() - - searchStartTime) - .count(); - if (elapsedSeconds >= DEFAULT_TIME && !hasSetSpecialTimeLimit) { - continueSearching = false; - } } return bestMove; -- cgit v1.2.3