aboutsummaryrefslogtreecommitdiff
path: root/src/bot.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bot.cpp')
-rw-r--r--src/bot.cpp27
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); }