diff --git a/source/tt.cpp b/source/tt.cpp index e7c1047..55d246e 100644 --- a/source/tt.cpp +++ b/source/tt.cpp @@ -2,8 +2,6 @@ static U64 initialSeed = 0x60919C48E57863B9; -TTEntry TTable[hashSize]; - // 2[colors] * 6[pieces] * 64[squares] U64 zKeys[2][6][64]; diff --git a/source/tt.h b/source/tt.h index 1913bc9..68d4db6 100644 --- a/source/tt.h +++ b/source/tt.h @@ -1,9 +1,7 @@ #pragma once #include "board.h" #include "search.h" - -// 5 MB -constexpr int hashSize = 0x500000; +#include // 2[colors] * 6[pieces] * 64[squares] extern U64 zKeys[2][6][64]; @@ -28,7 +26,9 @@ public: Move bestMove; }; -extern TTEntry TTable[hashSize]; +// 5 MB +inline int hashSize = 5000000 / sizeof(TTEntry); +inline std::vector TTable(hashSize); SearchResults ReadEntry(U64 &hashKey, int depth, int alpha, int beta); void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove); diff --git a/source/uci.cpp b/source/uci.cpp index 8a6367e..345c466 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -8,6 +8,7 @@ #include "search.h" #include "benchmark.h" #include +#include "tt.h" Move ParseMove(Board &board, const char* moveString) { GenerateMoves(board, board.sideToMove); @@ -155,6 +156,13 @@ void ParseGo(Board &board, std::string &command) { worker.detach(); } +static void SetOption(std::string &command) { + if (command.find("Hash") != std::string::npos) { + hashSize = (ReadParam("Hash", command) * 1000000) / sizeof(TTEntry); + TTable.resize(hashSize); + } +} + void UCILoop(Board &board) { // reset STDIN & STDOUT buffers setbuf(stdin, NULL); @@ -223,12 +231,16 @@ void UCILoop(Board &board) { // print engine info std::cout << "id name Eleanor\n"; std::cout << "id name rektdie\n"; - std::cout << "option name Hash type spin default 1 min 1 max 1\n"; + std::cout << "option name Hash type spin default 5 min 1 max 256\n"; std::cout << "option name Threads type spin default 1 min 1 max 1\n"; std::cout << "uciok\n"; continue; } + if (input.find("setoption") != std::string::npos) { + SetOption(input); + } + // Handling non-UCI "bench" command if (input.find("bench") != std::string::npos) { RunBenchmark();