aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-08-15 21:08:30 +0200
committerAdam <adammegarules1@gmail.com>2026-08-15 21:08:30 +0200
commit9702738db498cba05e7605afe1f48672f530e1a9 (patch)
treed9750295996e6ee336e59efdf8ef71804f45e210
parent242b2022ae234e252fe410b276e6d7c971147980 (diff)
removing maximum depth now insted we are gonna just have constant thinging time of 7 seconds for now if no time controls are speficied
-rw-r--r--src/bot.cpp57
-rw-r--r--src/main.cpp9
-rw-r--r--src/misc.hpp2
3 files changed, 42 insertions, 26 deletions
diff --git a/src/bot.cpp b/src/bot.cpp
index 03a0727..0e959d0 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -7,6 +7,7 @@
#include <cstdlib>
#include <iostream>
#include <iterator>
+#include <optional>
#include <ratio>
#include <vector>
@@ -16,7 +17,6 @@
#include "moves.hpp"
#include "zobrist.hpp"
-constexpr int MAXIMUM_DEPTH = 10;
constexpr int MAXIMUM_TIME_PER_MOVE = 7;
constexpr int Q_DEPTH_LIMIT = 4;
@@ -234,9 +234,10 @@ struct SearchResult {
int score;
};
-// Searches every root move to `depth` plies and returns the best one.
-// `previousBest` is the best move from the previous iteration (used for move
-// ordering, the core win of iterative deepening).
+/*
+ * Search nodes until depth X.
+ * Cutting everything bad using alpha-beta pruning.
+ */
static SearchResult SearchDepth(Game *b, int depth,
const uint16_t *previousBest) {
auto moves = GetSortedLegalMoves(b, true, previousBest);
@@ -273,18 +274,29 @@ static SearchResult SearchDepth(Game *b, int depth,
return {.bestMove = bestMove, .score = bestEval};
}
-static void PrintInfo(const int depth, const int engineScore,
- const uint64_t nps) {
- if (std::abs(engineScore) >= MATE_THRESHOLD) {
- int movesToMate = (MATE - std::abs(engineScore) + 1) / 2;
+struct Info {
+ const int depth;
+ const int score;
+ const std::optional<int> nodes;
+ const std::optional<int> nps;
+};
+static void PrintInfo(const Info &info) {
+
+ if (std::abs(info.score) >= MATE_THRESHOLD) {
+ int movesToMate = (MATE - std::abs(info.score) + 1) / 2;
movesToMate = std::max(1, movesToMate);
- std::cout << "info depth " << depth << " score mate "
- << (engineScore > 0 ? movesToMate : -movesToMate) << "\n"
+ std::cout << "info depth " << info.depth << " score mate "
+ << (info.score > 0 ? movesToMate : -movesToMate) << "\n"
<< std::flush;
} else {
- std::cout << "info depth " << depth << " score cp " << engineScore
- << " nodes " << Nodes << " nps " << nps << "\n"
- << std::flush;
+ std::cout << "info depth " << info.depth << " score cp " << info.score;
+ if (info.nodes.has_value()) {
+ std::cout << " nodes " << info.nodes.value();
+ }
+ if (info.nps.has_value()) {
+ std::cout << " nps " << info.nps.value();
+ }
+ std::cout << "\n" << std::flush;
}
}
@@ -292,8 +304,11 @@ uint16_t GetBestMove(Game *b, int maxDepth, move_options options) {
searchStopped = false;
Nodes = 0;
- int actualDepth = maxDepth > 0 ? maxDepth : MAXIMUM_DEPTH;
- bool usingDefaultDepth = maxDepth < 0;
+ // use depth INF if caller hasnt provided depth
+ int actualDepth = maxDepth > 0 ? maxDepth : INF;
+
+ bool hasSetSpecialTimeLimit = false;
+
auto legalMoves = GetSortedLegalMoves(b, true, nullptr);
if (legalMoves.empty()) {
assert(false && "GetBestMove called with no legal moves");
@@ -307,7 +322,7 @@ uint16_t GetBestMove(Game *b, int maxDepth, move_options options) {
timeToThingMS = INF; // to big number to ever achiave
if (options.wtime != -1 && options.btime != -1) {
- usingDefaultDepth = false;
+ hasSetSpecialTimeLimit = true;
int increment = b->turn ? options.wncr : options.bncr;
double time_remaning = b->turn ? options.wtime : options.btime;
@@ -339,7 +354,13 @@ uint16_t GetBestMove(Game *b, int maxDepth, move_options options) {
seconds > 0
? static_cast<uint64_t>(static_cast<double>(Nodes) / seconds)
: Nodes;
- PrintInfo(depth, result.score, nps);
+ Info info = {
+ .depth = depth,
+ .score = result.score,
+ .nodes = Nodes,
+ .nps = nps,
+ };
+ PrintInfo(info);
// A mate was found; deeper searches can only find a faster one.
if (std::abs(result.score) >= MATE_THRESHOLD) {
@@ -353,7 +374,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 && usingDefaultDepth) {
+ if (elapsedSeconds >= MAXIMUM_TIME_PER_MOVE && !hasSetSpecialTimeLimit) {
continueSearching = false;
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 09cb4d1..ade22c9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -18,19 +18,14 @@ static void perft(int argc, char *argv[]) {
exit(1);
}
- int depth = -1;
+ uint32_t depth = 0;
try {
- depth = std::stoi(argv[2]);
+ depth = static_cast<uint32_t>(std::stoi(argv[2]));
} catch (const std::exception &) {
std::cout << "info string usage: ./mono perft <non-negative depth>\n";
exit(1);
}
- if (depth < 0) {
- std::cout << "info string usage: ./mono perft <non-negative depth>\n";
- exit(1);
- }
-
std::string fen = argv[3];
auto start = std::chrono::steady_clock::now();
diff --git a/src/misc.hpp b/src/misc.hpp
index 6d269b0..b0ebe9a 100644
--- a/src/misc.hpp
+++ b/src/misc.hpp
@@ -7,6 +7,6 @@
std::string_view engine_info();
-uint64_t MoveGenTest(int depth, Game *g);
+uint64_t MoveGenTest(uint32_t depth, Game *g);
#endif /* SRC_MICS_H_ */