From 2f512931427121ea287cf2812ddf0b3fd6d7b83c Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 29 Jul 2026 11:16:11 +0200 Subject: saving cache to dish --- src/uci.cpp | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'src/uci.cpp') diff --git a/src/uci.cpp b/src/uci.cpp index b45df57..310d31c 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -17,11 +18,40 @@ #include #include -std::ofstream uciLog("uci_log.txt", std::ios::app); +std::ofstream uciLog("cache/uci_log.txt", std::ios::app); + +bool LoadTable( + const std::string &filename, + std::unordered_map *transpositions) { + std::ifstream file(filename); + + if (!file.is_open()) + return false; + + uint64_t hash; + int depth; + float eval; + + while (file >> hash >> depth >> eval) { + transpositions->operator[](hash) = {depth, eval}; + } + + return true; +} +void SaveTranspositionTable( + const std::unordered_map &table) { + + std::ofstream file("cache/positions.txt", std::ios::trunc); + + for (const auto &[key, value] : table) { + file << key << ' ' << value.depth << ' ' << value.Eval << '\n'; + } +}; void LogUci(const std::string &message) { - if (!uciLog.is_open()) + if (!uciLog.is_open()) { return; + } auto now = std::chrono::system_clock::now(); auto time = std::chrono::system_clock::to_time_t(now); @@ -76,7 +106,7 @@ void Uci() { Game game = initBoard("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", &transpositions); - + LoadTable("cache/positions.txt", &transpositions); string line; while (getline(cin, line)) { @@ -122,7 +152,7 @@ void Uci() { } } println(); - + SaveTranspositionTable(transpositions); cout.flush(); } else if (cmd.starts_with("position")) { stringstream ss(line); -- cgit v1.2.3