canCastleQueenSide static method
Checks if the given color (player) can castle queen side based on the board state.
Implementation
static bool canCastleQueenSide(ChessBoardInterface board, PieceColor color) {
if (hasLostCastlingRights(board, color, false)) {
return false; // Castling lost
}
int row = (color == PieceColor.white) ? 7 : 0;
if (board.getPiece(Position(row: row, col: 1)) != null ||
board.getPiece(Position(row: row, col: 2)) != null ||
board.getPiece(Position(row: row, col: 3)) != null) {
return false;
}
if (board.isKingInCheck()) return false;
ChessBoardInterface tempBoard = board.deepCopy();
tempBoard.movePiece(Position(row: row, col: 4), Position(row: row, col: 3));
if (tempBoard.isKingInCheck()) return false;
tempBoard = board.deepCopy();
tempBoard.movePiece(Position(row: row, col: 4), Position(row: row, col: 2));
if (tempBoard.isKingInCheck()) return false;
return true;
}