aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-07-29 19:55:22 +0200
committerAdam <adammegarules1@gmail.com>2026-07-29 19:55:22 +0200
commit4aac933e3c08535501558448ce43ce610b5e317f (patch)
treebfcf207dd7787d70e94017ed45f1af7e32106ade
parent1e57de844a1524b776167ccd7a1e822677d62527 (diff)
adding depth support
-rw-r--r--src/bot.cpp6
-rw-r--r--src/bot.hpp2
-rw-r--r--src/uci.cpp24
3 files changed, 23 insertions, 9 deletions
diff --git a/src/bot.cpp b/src/bot.cpp
index 4188308..916a311 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -10,8 +10,6 @@
#include <iostream>
#include <vector>
-const int SEARCH_DEPTH = 5;
-
const int PAWN_VALUE = 100;
const int KNIGHT_VALUE = 320;
const int BISHOP_VALUE = 400;
@@ -127,7 +125,7 @@ std::vector<Move> GetSortedLegalMoves(Game *g) {
return moves;
}
-Move EngineGetBestMove(Game *b) {
+Move EngineGetBestMove(Game *b, int depth) {
auto moves = GetSortedLegalMoves(b);
if (moves.size() == 0) {
std::cout << "Expected a position with legal moves";
@@ -142,7 +140,7 @@ Move EngineGetBestMove(Game *b) {
float alpha = -INFINITY;
float beta = INFINITY;
- float eval = minimax(SEARCH_DEPTH - 1, b, alpha, beta);
+ float eval = minimax(depth - 1, b, alpha, beta);
UnMakeMove(undo, b);
if (b->turn) {
diff --git a/src/bot.hpp b/src/bot.hpp
index 26ae9f2..0ca0d05 100644
--- a/src/bot.hpp
+++ b/src/bot.hpp
@@ -3,7 +3,7 @@
#include "board.hpp"
#include <vector>
-Move EngineGetBestMove(Game *b);
+Move EngineGetBestMove(Game *b, int depth);
float EvaluateBoardForWhite(Game *b, int depth);
float minimax(int depth, Game *b, float alpha, float beta);
int ScoreMove(const Game *board, const Move &move);
diff --git a/src/uci.cpp b/src/uci.cpp
index 8a7ad9a..e6aec4e 100644
--- a/src/uci.cpp
+++ b/src/uci.cpp
@@ -9,7 +9,6 @@
#include <cctype>
#include <cstdint>
#include <iostream>
-#include <print>
#include <sstream>
#include <string>
@@ -126,11 +125,27 @@ void Uci() {
cout << "readyok\n";
cout.flush();
} else if (cmd.starts_with("go")) {
- Move best = EngineGetBestMove(&game);
+
+ stringstream ss(line);
+
+ string token;
+ int depth = 4; // default depth
+
+ ss >> token; // go
+
+ while (ss >> token) {
+ if (token == "depth") {
+ ss >> depth;
+ break;
+ }
+ }
+
+ Move best = EngineGetBestMove(&game, depth);
cout << "bestmove ";
cout << (char)(best.From.file + 'a') << 8 - best.From.rank
<< (char)(best.To.file + 'a') << 8 - best.To.rank;
+
if (best.promotion != NONEPIECE) {
switch (best.promotion) {
case QUEEN:
@@ -146,10 +161,11 @@ void Uci() {
cout << "b";
break;
default:
- assert(false && "Unexepted promotion type");
+ assert(false && "Unexpected promotion type");
}
}
- println();
+
+ cout << "\n";
SaveTranspositionTable(transpositions);
cout.flush();
} else if (cmd.starts_with("position")) {