diff options
| author | Adam <adammegarules1@gmail.com> | 2026-07-29 08:49:58 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-07-29 08:49:58 +0200 |
| commit | 815abe7aabf47814dc391d19dedd6e9b23f100a1 (patch) | |
| tree | d7a957fef8a6ea5c00bd84bf1b8046004421785c /src/bot.cpp | |
| parent | ccb929172587fbfb8fb000d7992bdbbdac6f53ae (diff) | |
adding transpositions
Diffstat (limited to 'src/bot.cpp')
| -rw-r--r-- | src/bot.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/bot.cpp b/src/bot.cpp index 1a156a2..8a570e4 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -1,14 +1,16 @@ #include "bot.hpp" #include "board.hpp" #include "moves.hpp" +#include "zobrist.hpp" #include <algorithm> #include <cassert> #include <cmath> +#include <cstdint> #include <cstdlib> #include <iostream> #include <vector> -const int SEARCH_DEPTH = 4; +const int SEARCH_DEPTH = 5; const int PAWN_VALUE = 100; const int KNIGHT_VALUE = 320; @@ -132,17 +134,25 @@ float minimax(int depth, Game *b, float alpha, float beta) { if (depth == 0) { return EvaluateBoardForWhite(b, depth); } + uint64_t gameHash = GenerateZobristKey(b); + + if (b->Transpositions->contains(gameHash)) { + float value = b->Transpositions->at(gameHash); + return value; + } auto moves = GetLegalMoves(b); if (moves.size() == 0) { return EvaluateBoardForWhite(b, depth); } + float bestEval; if (b->turn) { - float bestEval = -INFINITY; + bestEval = -INFINITY; for (Move move : moves) { UndoMove undo = MakeMove(move, b); float eval = minimax(depth - 1, b, alpha, beta); + UnMakeMove(undo, b); bestEval = std::max(bestEval, eval); @@ -152,26 +162,27 @@ float minimax(int depth, Game *b, float alpha, float beta) { break; } } - - return bestEval; } else { - float BestEval = INFINITY; + bestEval = INFINITY; for (Move move : moves) { UndoMove undo = MakeMove(move, b); float eval = minimax(depth - 1, b, alpha, beta); + UnMakeMove(undo, b); - BestEval = std::min(BestEval, eval); + bestEval = std::min(bestEval, eval); - beta = std::min(beta, BestEval); + beta = std::min(beta, bestEval); if (alpha >= beta) { break; // *snips* } } - return BestEval; } + + b->Transpositions->operator[](gameHash) = bestEval; + return bestEval; } int PSTIndex(int square, bool white) { return white ? square : (56 ^ square); } |
