- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtb.cpp
More file actions
Latest commit
59 lines (47 loc) · 1.52 KB
/
Copy pathtb.cpp
File metadata and controls
59 lines (47 loc) · 1.52 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
56
57
58
59
#include"tb.h"
#include<exception>
#include<iostream>
#include<tbprobe.h>
#include<unordered_set>
namespaceengine::tb {
tbprobe::syzygy::Tablebase tablebase;
namespace {
std::size_tunique_table_count(const std::unordered_map<std::string, tbprobe::syzygy::Table *> &tables) {
std::unordered_set<const tbprobe::syzygy::Table *> uniqueTables;
for (constauto &[_, table] : tables)
if (table != nullptr)
uniqueTables.insert(table);
return uniqueTables.size();
}
} // namespace
voidinit(const std::string &path) {
tablebase.close();
if (path.empty()) {
std::cout << "info string Found 0 WDL and 0 DTZ tablebase files\n";
return;
}
try {
tbprobe::syzygy::initialize();
tablebase.add_directory(path, true, true);
std::cout << "info string Found " << wdl_count() << " WDL and " << dtz_count() << " DTZ tablebase files\n";
} catch (const std::exception &e) {
std::cout << "info string Syzygy init failed: " << e.what() << '\n';
}
}
std::size_twdl_count() { returnunique_table_count(tablebase.wdl); }
std::size_tdtz_count() { returnunique_table_count(tablebase.dtz); }
intprobe_wdl(chess::Position &board) {
try {
return *tablebase.get_wdl(board, TB_ERROR);
} catch (const std::exception &) {
returnTB_ERROR;
}
}
intprobe_dtz(chess::Position &board) {
try {
return *tablebase.get_dtz(board, TB_ERROR);
} catch (const std::exception &) {
returnTB_ERROR;
}
}
} // namespace engine::tb