-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtb.cpp
More file actions
55 lines (43 loc) · 1.38 KB
/
tb.cpp
File metadata and controls
55 lines (43 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "tb.h"
#include <exception>
#include <iostream>
#include <tbprobe.h>
#include <unordered_set>
namespace engine::tb {
tbprobe::syzygy::Tablebase tablebase;
namespace {
std::size_t unique_table_count(const std::unordered_map<std::string, tbprobe::syzygy::Table *> &tables) {
std::unordered_set<const tbprobe::syzygy::Table *> uniqueTables;
for (const auto &[_, table] : tables)
if (table != nullptr)
uniqueTables.insert(table);
return uniqueTables.size();
}
} // namespace
void init(const std::string &path) {
tablebase.close();
if (path.empty()) {
std::cout << "info string Found 0 WDL and 0 DTZ tablebase files\n";
return;
}
tbprobe::syzygy::initialize();
tablebase.add_directory(path, true, true);
std::cout << "info string Found " << wdl_count() << " WDL and " << dtz_count() << " DTZ tablebase files\n";
}
std::size_t wdl_count() { return unique_table_count(tablebase.wdl); }
std::size_t dtz_count() { return unique_table_count(tablebase.dtz); }
int probe_wdl(chess::Board &board) {
try {
return *tablebase.get_wdl(board, TB_ERROR);
} catch (const std::exception &) {
return TB_ERROR;
}
}
int probe_dtz(chess::Board &board) {
try {
return *tablebase.get_dtz(board, TB_ERROR);
} catch (const std::exception &) {
return TB_ERROR;
}
}
} // namespace engine::tb