diff options
Diffstat (limited to 'src/bot.cpp')
| -rw-r--r-- | src/bot.cpp | 21 |
1 files 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 <cmath> #include <cstdint> #include <cstdlib> +#include <exception> #include <iostream> #include <iterator> #include <optional> @@ -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<double>(std::chrono::steady_clock::now() - - searchStartTime) - .count(); - if (elapsedSeconds >= DEFAULT_TIME && !hasSetSpecialTimeLimit) { - continueSearching = false; - } } return bestMove; |
