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
+17
-12
@@ -68,8 +68,21 @@ public:
|
||||
return (GetFlags() == kingCastle || GetFlags() == queenCastle);
|
||||
}
|
||||
|
||||
// Castling moves are stored as "king takes own castling rook": from = king square, to = rook square.
|
||||
// This is the UCI_Chess960 notation and it can't clash with a normal king move.
|
||||
// CastleKingDest() is the square the king actually ends up on (g/c file of the back rank).
|
||||
int CastleKingDest() {
|
||||
return (MoveTo() & ~7) + (GetFlags() == kingCastle ? 6 : 2);
|
||||
}
|
||||
|
||||
// Destination square used when printing the move: standard UCI prints the king's
|
||||
// destination (e1g1), UCI_Chess960 prints the rook square (e1h1).
|
||||
int PrintTo() {
|
||||
return (IsCastle() && !UCIChess960) ? CastleKingDest() : MoveTo();
|
||||
}
|
||||
|
||||
void PrintMove() {
|
||||
std::cout << squareCoords[MoveFrom()] << squareCoords[MoveTo()];
|
||||
std::cout << squareCoords[MoveFrom()] << squareCoords[PrintTo()];
|
||||
|
||||
int flags = GetFlags();
|
||||
|
||||
@@ -86,7 +99,7 @@ public:
|
||||
|
||||
std::string GetMoveString() {
|
||||
std::string result = squareCoords[MoveFrom()];
|
||||
result += squareCoords[MoveTo()];
|
||||
result += squareCoords[PrintTo()];
|
||||
|
||||
int flags = GetFlags();
|
||||
|
||||
@@ -110,16 +123,8 @@ public:
|
||||
viriMove = MoveFrom();
|
||||
|
||||
if (flags == kingCastle || flags == queenCastle) {
|
||||
uint16_t moveTo = 0;
|
||||
bool side = (MoveFrom() / 8 == 0) ? White : Black;
|
||||
|
||||
if (flags == kingCastle) {
|
||||
moveTo = (side == White) ? h1 : h8;
|
||||
} else {
|
||||
moveTo = (side == White) ? a1 : a8;
|
||||
}
|
||||
|
||||
viriMove |= (moveTo << 6);
|
||||
// Castling is already stored as king takes rook, which is what the viri format expects
|
||||
viriMove |= (MoveTo() << 6);
|
||||
|
||||
viriMove |= 0x8000;
|
||||
|
||||
|
||||
Reference in new issue
Block a user