Skip to content

Commit

Permalink
[#72] Fixed king castle in heaven without rook
Browse files Browse the repository at this point in the history
  • Loading branch information
Ido-Barnea committed Oct 27, 2023
1 parent 63e908a commit 42dfb88
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions development/src/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,13 @@ function castle(kingPiece: Piece, targetSquare: Square) {
const deltaX = targetSquare.position.coordinates[0] - kingPiece.position.coordinates[0];
// Depends on if it's Kingside or Queenside castling
const isKingsideCastling = deltaX > 0;
const rookFilter = (piece: Piece) =>
isKingsideCastling
const rookFilter = (piece: Piece) => {
const isValidCastling = isKingsideCastling
? piece.position.coordinates[0] > kingPiece.position.coordinates[0]
: piece.position.coordinates[0] < kingPiece.position.coordinates[0];
const areOnTheSameBoard = piece.position.board === kingPiece.position.board;
return isValidCastling && areOnTheSameBoard;
};
const rookPiece = possibleRooks.find(rookFilter);
if (!rookPiece) return false;

Expand Down

0 comments on commit 42dfb88

Please sign in to comment.