Add Chess960 (FRC) and DFRC support

- castling moves are stored as "king takes own rook" (from = king square, to = castling rook square)
- per-colour castling rook squares (Board::castleRook), so DFRC (different back ranks for white/black) works
- FEN parsing/printing: KQkq (X-FEN) and Shredder-FEN file letters
- Board::CanCastle(): generic castling legality (empty paths, king not attacked, rook x-ray check)
- MakeMove handles arbitrary king/rook start squares (king and rook may stay in place or swap through each other's squares)
- UCI_Chess960 option: castling printed/parsed as king-takes-rook when on, standard e1g1 style otherwise (both are accepted when parsing)
- viri format, perft castle check and castling right updates no longer assume a1/h1/a8/h8
This commit is contained in:
claude committed 2026-10-11 00:12:02 +02:00
1 parent e984510434
commit aa97abaadc
9 files changed
+247 -71

No files matched your search

+22 -6
View File
@@ -152,12 +152,28 @@ Move parseMove(Board &board, std::string_view str) {
}
}
} else {
for (Move move : board.moveList) {
bool found = false;
// Exact match first. Castling moves are stored as "king takes own rook",
// so this also covers the UCI_Chess960 castling notation (e1h1).
for (int i = 0; i < board.currentMoveIndex; i++) {
Move move = board.moveList[i];
if (move.MoveFrom() == from && move.MoveTo() == to) {
flag = move.GetFlags();
found = true;
break;
}
}
// Standard UCI castling notation: the king's destination square (e1g1)
if (!found) {
for (int i = 0; i < board.currentMoveIndex; i++) {
Move move = board.moveList[i];
if (move.IsCastle() && move.MoveFrom() == from && move.CastleKingDest() == to) {
return move;
}
}
}
}
return Move(from, to, flag);
@@ -177,11 +193,11 @@ std::array<uint8_t, 16> CompressPieces(Board board) {
int pieceCode = pieceType;
if (pieceType == Rook) {
if ((square == a1 && (board.castlingRights & whiteQueenRight))
|| (square == h1 && (board.castlingRights & whiteKingRight))
|| (square == a8 && (board.castlingRights & blackQueenRight))
|| (square == h8 && (board.castlingRights & blackKingRight)))
pieceCode = UNMOVED_ROOK;
// castling rooks, wherever they started (Chess960 aware)
for (int idx = 0; idx < 4; idx++) {
if ((board.castlingRights & (1 << idx)) && square == board.castleRook[idx] && pieceColor == (idx >> 1))
pieceCode = UNMOVED_ROOK;
}
}
pieceCode |= (pieceColor << 3); // Shift the color to the 3rd bit (bit 3)