From 0528ed43bb13edd89dfa8a38b9bfca6ba7fd83d6 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 30 Jul 2026 17:19:56 +0200 Subject: optimazing --- src/bot.cpp | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'src/bot.cpp') 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 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 GetSortedLegalMoves(Game *g) { - auto moves = GetLegalMoves(g); +std::vector 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 attackMoves; - for (Move move : GetSortedLegalMoves(b)) { - if (b->pieces[PositionToIndex(move.To)].type != NONEPIECE) { - attackMoves.push_back(move); - } - }; + std::vector attackMoves = GetSortedLegalMoves(b, false); if (attackMoves.empty()) { return standPat; } - int bestEval = b->turn ? std::numeric_limits::lowest() - : std::numeric_limits::max(); + int bestScore = b->turn ? std::numeric_limits::lowest() + : std::numeric_limits::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::lowest() - : std::numeric_limits::max(); + int bestScore = b->turn ? std::numeric_limits::lowest() + : std::numeric_limits::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(bestEval)); + alpha = std::max(alpha, static_cast(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(bestEval)); + beta = std::min(beta, static_cast(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) { -- cgit v1.2.3