aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-08-24 17:06:42 +0200
committerAdam <adammegarules1@gmail.com>2026-08-24 17:06:42 +0200
commitac99b1562391201b954c3b9dbd3c81a3050197a4 (patch)
tree8ba53a1f8b0504b6d5b996c7026287467279a3d9
parent516a65fd163390b9095b98d8dd7338440be7e1c5 (diff)
feat(search): removing double clock check and instalny finish search with only one legal movesHEADmain
-rw-r--r--src/bot.cpp21
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;