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:
1 parent
e984510434
commit
aa97abaadc
9 files changed
+247
-71
No files matched your search
+5
-22
@@ -241,28 +241,11 @@ void GenKingMoves(Board &board) {
|
||||
moves.PopBit(square);
|
||||
}
|
||||
|
||||
// Generating castles
|
||||
int kingRight = board.sideToMove ? blackKingRight : whiteKingRight;
|
||||
int queenRight = board.sideToMove ? blackQueenRight : whiteQueenRight;
|
||||
|
||||
if (board.castlingRights & queenRight) {
|
||||
U64 QueenSide = board.sideToMove ? 0x1f00000000000000 : 0x1f;
|
||||
U64 mask = board.sideToMove ? 0x1c00000000000000 : 0x1c;
|
||||
int targetSquare = board.sideToMove ? c8 : c1;
|
||||
if ((Bitboard(QueenSide) & board.occupied).PopCount() == 2
|
||||
&& !(mask & board.colorThreats[!board.sideToMove])) {
|
||||
board.AddMove(Move(kingSquare, targetSquare, queenCastle));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (board.castlingRights & kingRight) {
|
||||
U64 KingSide = board.sideToMove ? 0xf000000000000000 : 0xf0;
|
||||
U64 mask = board.sideToMove ? 0x7000000000000000 : 0x70;
|
||||
int targetSquare = board.sideToMove ? g8 : g1;
|
||||
if ((Bitboard(KingSide) & board.occupied).PopCount() == 2
|
||||
&& !(mask & board.colorThreats[!board.sideToMove])) {
|
||||
board.AddMove(Move(kingSquare, targetSquare, kingCastle));
|
||||
// Generating castles (Chess960 aware): encoded as the king taking its own castling rook
|
||||
for (const bool kingSide : {false, true}) {
|
||||
if (board.CanCastle(board.sideToMove, kingSide)) {
|
||||
board.AddMove(Move(kingSquare, board.castleRook[Board::CastleIdx(board.sideToMove, kingSide)],
|
||||
kingSide ? kingCastle : queenCastle));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user