aboutsummaryrefslogtreecommitdiff
path: root/src/bot.cpp
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-07-30 17:19:56 +0200
committerAdam <adammegarules1@gmail.com>2026-07-30 17:19:56 +0200
commit0528ed43bb13edd89dfa8a38b9bfca6ba7fd83d6 (patch)
tree4b7dbb7d2f2875a761629da5fe290f7680a46bea /src/bot.cpp
parent8df9e390a71eeb2835eab06ec4b474c8cad63ecd (diff)
optimazing
Diffstat (limited to 'src/bot.cpp')
-rw-r--r--src/bot.cpp41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/bot.cpp b/src/bot.cpp
index f05c303..61c38fa 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -11,7 +11,7 @@
#include <vector>
constexpr int DEFAULT_DEPTH = 4;
-constexpr int Q_DEPTH_LIMIT = 6;
+constexpr int Q_DEPTH_LIMIT = 3;
constexpr int PAWN_VALUE = 100;
constexpr int KNIGHT_VALUE = 320;
@@ -117,8 +117,8 @@ int ScoreMove(const Game *board, const Move &move) {
return score;
}
-std::vector<Move> GetSortedLegalMoves(Game *g) {
- auto moves = GetLegalMoves(g);
+std::vector<Move> GetSortedLegalMoves(Game *g, bool generateQuietMoves) {
+ auto moves = GetLegalMoves(g, generateQuietMoves);
if (moves.empty()) {
return moves;
}
@@ -167,18 +167,13 @@ int quiescenceSearch(Game *b, int Qdepth) {
if (Qdepth >= Q_DEPTH_LIMIT) {
return standPat;
}
- std::vector<Move> attackMoves;
- for (Move move : GetSortedLegalMoves(b)) {
- if (b->pieces[PositionToIndex(move.To)].type != NONEPIECE) {
- attackMoves.push_back(move);
- }
- };
+ std::vector<Move> attackMoves = GetSortedLegalMoves(b, false);
if (attackMoves.empty()) {
return standPat;
}
- int bestEval = b->turn ? std::numeric_limits<int>::lowest()
- : std::numeric_limits<int>::max();
+ int bestScore = b->turn ? std::numeric_limits<int>::lowest()
+ : std::numeric_limits<int>::max();
if (b->turn) {
for (Move move : attackMoves) {
@@ -187,7 +182,7 @@ int quiescenceSearch(Game *b, int Qdepth) {
int eval = quiescenceSearch(b, Qdepth + 1);
UnMakeMove(undo, b);
- bestEval = std::max(bestEval, eval);
+ bestScore = std::max(bestScore, eval);
}
} else {
for (Move move : attackMoves) {
@@ -196,11 +191,11 @@ int quiescenceSearch(Game *b, int Qdepth) {
int eval = quiescenceSearch(b, Qdepth + 1);
UnMakeMove(undo, b);
- bestEval = std::min(bestEval, eval);
+ bestScore = std::min(bestScore, eval);
}
}
- return bestEval;
+ return bestScore;
}
int minimax(int depth, Game *b, float alpha, float beta) {
@@ -221,13 +216,13 @@ int minimax(int depth, Game *b, float alpha, float beta) {
}
auto moves = GetSortedLegalMoves(b);
if (moves.empty()) {
- return quiescenceSearch(b, 0);
+ return EvaluateBoardForWhite(b);
}
bool shouldStore = true;
- int bestEval = b->turn ? std::numeric_limits<int>::lowest()
- : std::numeric_limits<int>::max();
+ int bestScore = b->turn ? std::numeric_limits<int>::lowest()
+ : std::numeric_limits<int>::max();
if (b->turn) {
for (Move move : moves) {
@@ -236,9 +231,9 @@ int minimax(int depth, Game *b, float alpha, float beta) {
int eval = minimax(depth - 1, b, alpha, beta);
UnMakeMove(undo, b);
- bestEval = std::max(bestEval, eval);
+ bestScore = std::max(bestScore, eval);
- alpha = std::max(alpha, static_cast<float>(bestEval));
+ alpha = std::max(alpha, static_cast<float>(bestScore));
if (alpha >= beta) {
shouldStore = false;
@@ -252,9 +247,9 @@ int minimax(int depth, Game *b, float alpha, float beta) {
int eval = minimax(depth - 1, b, alpha, beta);
UnMakeMove(undo, b);
- bestEval = std::min(bestEval, eval);
+ bestScore = std::min(bestScore, eval);
- beta = std::min(beta, static_cast<float>(bestEval));
+ beta = std::min(beta, static_cast<float>(bestScore));
if (alpha >= beta) {
shouldStore = false;
break; // *snips*
@@ -264,9 +259,9 @@ int minimax(int depth, Game *b, float alpha, float beta) {
if (shouldStore) {
b->Transpositions->operator[](gameHash) = {.depth = depth,
- .Eval = bestEval};
+ .Eval = bestScore};
}
- return bestEval;
+ return bestScore;
}
static int PSTIndex(const int square, const bool white) {