diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/board.hpp | 7 | ||||
| -rw-r--r-- | src/bot.cpp | 8 | ||||
| -rw-r--r-- | src/uci.cpp | 7 | ||||
| -rw-r--r-- | src/uci.hpp | 5 |
4 files changed, 17 insertions, 10 deletions
diff --git a/src/board.hpp b/src/board.hpp index 687510e..4f04783 100644 --- a/src/board.hpp +++ b/src/board.hpp @@ -35,7 +35,10 @@ struct Position { bool operator==(const Position &) const = default; }; - +struct TranspositionsEntry { + int depth; + float Eval; +}; struct Game { Piece pieces[64]; bool turn = 1; // 1 white; 0 black @@ -46,7 +49,7 @@ struct Game { bool canEnpassant = 0; GameState state = TURN; std::unordered_map<uint64_t, int> ThreeFoldMap; - std::unordered_map<uint64_t, float> *Transpositions = nullptr; + std::unordered_map<uint64_t, TranspositionsEntry> *Transpositions = nullptr; }; struct Move { diff --git a/src/bot.cpp b/src/bot.cpp index 8a570e4..3394ae2 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -137,8 +137,10 @@ float minimax(int depth, Game *b, float alpha, float beta) { uint64_t gameHash = GenerateZobristKey(b); if (b->Transpositions->contains(gameHash)) { - float value = b->Transpositions->at(gameHash); - return value; + TranspositionsEntry data = b->Transpositions->at(gameHash); + if (data.depth >= depth) { + return data.Eval; + } } auto moves = GetLegalMoves(b); if (moves.size() == 0) { @@ -181,7 +183,7 @@ float minimax(int depth, Game *b, float alpha, float beta) { } } - b->Transpositions->operator[](gameHash) = bestEval; + b->Transpositions->operator[](gameHash) = {depth, bestEval}; return bestEval; } int PSTIndex(int square, bool white) { return white ? square : (56 ^ square); } diff --git a/src/uci.cpp b/src/uci.cpp index b4e384a..b45df57 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -45,8 +45,9 @@ Move UciToMove(string uci) { return {from, to}; } -Game initBoard(string startingFEN, - std::unordered_map<uint64_t, float> *transPositions) { +Game initBoard( + string startingFEN, + std::unordered_map<uint64_t, TranspositionsEntry> *transPositions) { Game b{}; b.enPassant = IndexToPosition(0); // default value b.canEnpassant = false; @@ -71,7 +72,7 @@ Game initBoard(string startingFEN, return b; }; void Uci() { - unordered_map<uint64_t, float> transpositions = {}; + unordered_map<uint64_t, TranspositionsEntry> transpositions = {}; Game game = initBoard("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", &transpositions); diff --git a/src/uci.hpp b/src/uci.hpp index 4d84215..9352c48 100644 --- a/src/uci.hpp +++ b/src/uci.hpp @@ -7,6 +7,7 @@ Move UciToMove(std::string uci); void LogUci(const std::string &message); void Uci(); -Game initBoard(std::string startingFEN, - std::unordered_map<uint64_t, float> *transPositions); +Game initBoard( + std::string startingFEN, + std::unordered_map<uint64_t, TranspositionsEntry> *transPositions); #endif /* SRC_UCI_H_ */ |
