feat: Chess960 support
Castling works with any rook placement: each castling right remembers its rook square (Position::castle_rook), set from KQkq (X-FEN, the outermost rook on that side of the king) or Shredder-FEN file letters. Castling moves stay king-from to king-destination (g/c file), so move indices, history tables and the bench are unchanged; make_move lifts king and rook before placing them, since in 960 their squares can overlap. Rights are dropped by a king move or a move from or to a castling rook's square. Generation follows the 960 rules: every square the king or rook crosses or lands on is empty apart from the two, and no square the king crosses or lands on is attacked with the moving rook out of the occupancy (the king's own square included when it does not move: the rook leaving can uncover the rank). has_legal_move falls back to full generation for non-standard castling setups. UCI_Chess960 writes and reads castling as the king taking its rook; FEN output uses KQkq for outermost rooks and file letters otherwise. New command perftfile <epd> [depth] runs an EPD perft file. Checked: the 960 positions of the standard Chess960 perft suite (fischer.epd) all match to depth 5 (17.6 billion nodes), perftsuite 6 passes, has_legal_move agrees with full generation at every perft node to depth 4 of the 960 suite, castling both ways over UCI in 960 mode. Lc0's training data has about 4% Chess960 games, which the policy data converter now keeps. Bench: 529903 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1dacc9c402
commit
9643c7b0a5
10 files changed
+203
-57
No files matched your search
+14
-1
@@ -53,6 +53,7 @@ void print_id() {
|
||||
send("option name Hash type spin default " + std::to_string(DEFAULT_HASH_MB) + " min 1 max 65536");
|
||||
send("option name Threads type spin default 1 min 1 max 1");
|
||||
send("option name MoveOverhead type spin default 20 min 0 max 5000");
|
||||
send("option name UCI_Chess960 type check default false");
|
||||
// Search constants, exposed as integers (x100) so SPSA can tune them.
|
||||
send("option name CPuct type spin default 160 min 1 max 1000");
|
||||
send("option name RootCPuct type spin default 233 min 1 max 1000");
|
||||
@@ -70,6 +71,11 @@ void set_option(Engine& e, std::istringstream& is) {
|
||||
std::string lname = name;
|
||||
std::transform(lname.begin(), lname.end(), lname.begin(), [](unsigned char c) { return char(std::tolower(c)); });
|
||||
|
||||
if (lname == "uci_chess960") {
|
||||
chess960 = value == "true";
|
||||
return;
|
||||
}
|
||||
|
||||
int v = 0;
|
||||
try {
|
||||
v = std::stoi(value);
|
||||
@@ -148,7 +154,7 @@ void go(Engine& e, std::istringstream& is) {
|
||||
e.searcher.stop_flag = false;
|
||||
e.worker = std::thread([&e, pos = e.pos, history = e.history, limits] {
|
||||
const SearchResult result = e.searcher.search(pos, history, limits, true);
|
||||
send(e.searcher.pretty ? pretty::bestmove(pos, result.best) : "bestmove " + result.best.to_uci());
|
||||
send(e.searcher.pretty ? pretty::bestmove(pos, result.best) : "bestmove " + pos.uci(result.best));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -273,6 +279,13 @@ void uci_loop() {
|
||||
is >> depth;
|
||||
e.stop();
|
||||
perft_suite(depth);
|
||||
} else if (cmd == "perftfile") {
|
||||
// perftfile <epd> [max depth]: lines of "<fen> ;D1 <nodes> ;D2 <nodes> ..."
|
||||
std::string path;
|
||||
int depth = 6;
|
||||
is >> path >> depth;
|
||||
e.stop();
|
||||
perft_file(path, depth);
|
||||
} else if (cmd == "bench") {
|
||||
int playouts = DEFAULT_BENCH_PLAYOUTS;
|
||||
is >> playouts;
|
||||
|
||||
Reference in new issue
Block a user