aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-08-16 15:21:08 +0200
committerAdam <adammegarules1@gmail.com>2026-08-16 15:21:08 +0200
commit55ccaf0c531e1bea330f65c8d2f1c739819c2459 (patch)
tree925dc53171f5f2408bbc10e76e1e0545b3d3f9f1
parent6920bb291cb156a976f5edadb25c17e86dfa716f (diff)
fix(search) making quiecen search have same mid search logic as main search
-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;
}
}