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
@@ -12,6 +12,11 @@ namespace zobrist {
|
||||
void init();
|
||||
}
|
||||
|
||||
// UCI_Chess960: castling moves are written as the king taking its own rook
|
||||
// (e1h1) instead of the king's destination (e1g1). Positions themselves always
|
||||
// support any castling rook placement.
|
||||
inline bool chess960 = false;
|
||||
|
||||
// Plain copy-make position. Small enough to copy at every tree step.
|
||||
struct Position {
|
||||
u64 pieces[6] = {};
|
||||
@@ -19,6 +24,9 @@ struct Position {
|
||||
u8 board[64];
|
||||
int stm = WHITE;
|
||||
int castling = 0;
|
||||
// The rook each castling right moves, indexed by the right's bit
|
||||
// (WHITE_OO, WHITE_OOO, BLACK_OO, BLACK_OOO).
|
||||
u8 castle_rook[4] = {H1, A1, H8, A8};
|
||||
int ep = NO_SQUARE; // only set when a capture there is pseudo-legal
|
||||
int halfmove = 0;
|
||||
int fullmove = 1;
|
||||
@@ -44,6 +52,14 @@ struct Position {
|
||||
|
||||
// Returns a null move when the string is not a legal move here.
|
||||
Move parse_uci(std::string_view uci) const;
|
||||
// The move in UCI notation, castling written as chess960 asks. Works for
|
||||
// any move of the game (the castling rooks never change), so the root
|
||||
// position can print a whole PV.
|
||||
std::string uci(Move m) const;
|
||||
// The rook a castling move takes along; the king's rank tells the colour.
|
||||
int castle_rook_square(Move m) const {
|
||||
return castle_rook[(rank_of(m.from()) == 0 ? 0 : 2) + (m.flag() == Move::QUEEN_CASTLE)];
|
||||
}
|
||||
|
||||
std::string pretty() const;
|
||||
|
||||
|
||||
Reference in new issue
Block a user