-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
112 lines (100 loc) · 3.77 KB
/
Copy pathmain.cpp
File metadata and controls
112 lines (100 loc) · 3.77 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <filesystem>
#include <iostream>
#include <string>
#include <system_error>
#include <vector>
#include <charconv>
#include <cstdint>
#include "tests/perfts.h"
#include "tests/nnue_consistency.h"
#include "src/uci/uci.h"
namespace {
std::string resolve_epd_path(const std::string& explicitPath, const char* argv0) {
namespace fs = std::filesystem;
std::vector<fs::path> candidates;
if (!explicitPath.empty()) {
candidates.emplace_back(explicitPath);
} else {
candidates.emplace_back("test_data/standard.epd");
candidates.emplace_back("../test_data/standard.epd");
candidates.emplace_back("../../test_data/standard.epd");
std::error_code ec;
fs::path exePath = fs::absolute(fs::path(argv0), ec);
if (!ec) {
fs::path probe = exePath.parent_path();
for (int i = 0; i < 8 && !probe.empty(); ++i) {
candidates.push_back(probe / "test_data" / "standard.epd");
const fs::path parent = probe.parent_path();
if (parent == probe) break;
probe = parent;
}
}
}
std::error_code ec;
for (const fs::path& p : candidates) {
if (!p.empty() && fs::exists(p, ec)) {
const fs::path normalized = fs::weakly_canonical(p, ec);
if (!ec) return normalized.string();
return p.string();
}
ec.clear();
}
return "";
}
bool parse_positive_int(const std::string& token, int& out) {
int value = 0;
const char* begin = token.data();
const char* end = token.data() + token.size();
const auto [ptr, ec] = std::from_chars(begin, end, value);
if (ec != std::errc() || ptr != end || value <= 0) return false;
out = value;
return true;
}
bool parse_u64(const std::string& token, uint64_t& out) {
uint64_t value = 0;
const char* begin = token.data();
const char* end = token.data() + token.size();
const auto [ptr, ec] = std::from_chars(begin, end, value);
if (ec != std::errc() || ptr != end) return false;
out = value;
return true;
}
}
int main(int argc, char** argv) {
if (argc > 1 && std::string(argv[1]) == "--nnue-consistency") {
int games = 32;
int maxPlies = 80;
uint64_t seed = 0xC0FFEEULL;
if (argc > 2 && !parse_positive_int(argv[2], games)) {
std::cerr << "[ERROR] Invalid games value for --nnue-consistency.\n";
return 1;
}
if (argc > 3 && !parse_positive_int(argv[3], maxPlies)) {
std::cerr << "[ERROR] Invalid max-plies value for --nnue-consistency.\n";
return 1;
}
if (argc > 4 && !parse_u64(argv[4], seed)) {
std::cerr << "[ERROR] Invalid seed value for --nnue-consistency.\n";
return 1;
}
if (argc > 5) {
std::cerr
<< "[ERROR] Usage: --nnue-consistency [games] [max-plies] [seed]\n";
return 1;
}
return run_nnue_incremental_consistency_test(games, maxPlies, seed);
}
if (argc > 1 && std::string(argv[1]) == "--perft") {
const std::string requested = argc > 2 ? std::string(argv[2]) : "";
const std::string epdPath = resolve_epd_path(requested, argv[0]);
if (epdPath.empty()) {
std::cerr
<< "[ERROR] Could not locate EPD file. "
<< "Provide one explicitly with: --perft <path-to-standard.epd>\n";
return 1;
}
std::cout << "Starting Chess Engine Core...\n";
return run_epd_test_suite(epdPath, 5);
}
return UCI::run();
}