aboutsummaryrefslogtreecommitdiff
path: root/src/uci.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/uci.cpp')
-rw-r--r--src/uci.cpp38
1 files changed, 34 insertions, 4 deletions
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 <algorithm>
#include <cassert>
#include <cctype>
+#include <cstdint>
#include <iostream>
#include <print>
#include <sstream>
@@ -17,11 +18,40 @@
#include <iomanip>
#include <unordered_map>
-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<uint64_t, TranspositionsEntry> *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<uint64_t, TranspositionsEntry> &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);