aboutsummaryrefslogtreecommitdiff
path: root/src/bot.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bot.cpp')
-rw-r--r--src/bot.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/bot.cpp b/src/bot.cpp
index 7abe516..b09a704 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -17,7 +17,7 @@
#include "moves.hpp"
#include "zobrist.hpp"
-constexpr int MAXIMUM_TIME_PER_MOVE = 7;
+constexpr int DEFAULT_TIME = 7;
constexpr int Q_DEPTH_LIMIT = 4;
constexpr int MATE = 10000;
@@ -95,7 +95,21 @@ static std::vector<uint16_t> GetSortedLegalMoves(Game *g,
}
static int quiescenceSearch(Game *b, int qdepth, int alpha, int beta, int ply) {
+ if (timeToThingMS == -1) {
+ assert(false && "Expected set time: internal error");
+ exit(1);
+ }
Nodes++;
+ if ((Nodes & 2047) == 0) {
+ double elapsedMiliseconds =
+ std::chrono::duration<double, std::milli>(
+ std::chrono::steady_clock::now() - searchStartTime)
+ .count();
+ if (elapsedMiliseconds >= timeToThingMS) {
+ searchStopped = true;
+ return 0;
+ }
+ }
const int standPat = EvaluateBoard(b);
@@ -128,6 +142,9 @@ static int quiescenceSearch(Game *b, int qdepth, int alpha, int beta, int ply) {
int score = -quiescenceSearch(b, qdepth + 1, -beta, -alpha, ply + 1);
UndoMove(undo, b);
+ if (searchStopped) {
+ return 0;
+ }
if (score >= beta) {
return beta;
@@ -318,7 +335,7 @@ uint16_t GetBestMove(Game *b, int maxDepth, move_options options) {
searchStartTime = std::chrono::steady_clock::now();
- timeToThingMS = INF; // to big number to ever achiave
+ timeToThingMS = DEFAULT_TIME * 1000; // to big number to ever achiave
if (options.wtime != -1 && options.btime != -1) {
hasSetSpecialTimeLimit = true;
@@ -373,7 +390,7 @@ uint16_t GetBestMove(Game *b, int maxDepth, move_options options) {
std::chrono::duration<double>(std::chrono::steady_clock::now() -
searchStartTime)
.count();
- if (elapsedSeconds >= MAXIMUM_TIME_PER_MOVE && !hasSetSpecialTimeLimit) {
+ if (elapsedSeconds >= DEFAULT_TIME && !hasSetSpecialTimeLimit) {
continueSearching = false;
}
}