From 815abe7aabf47814dc391d19dedd6e9b23f100a1 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 29 Jul 2026 08:49:58 +0200 Subject: adding transpositions --- src/bot.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/bot.cpp') 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 #include #include +#include #include #include #include -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); } -- cgit v1.2.3