diff --git a/js/chess.js b/js/chess.js index 23e0a2a..860433a 100644 --- a/js/chess.js +++ b/js/chess.js @@ -161,18 +161,24 @@ function legalMoves(board, side, type, from, canCapture){ scanPath(legals, board, side, from, false, dir[0], dir[1], 0); } if (from[0] === 'e' && from[1] === (isDark(side) ? '8' : '1')) { + const other = otherSide(side); /* check for castling conditions */ if (!hasMoved(board, side, from)) { if (boardGet(board, 'f' + from[1], side) === ' ' && + boardGet(board, 'f' + from[1], other) === ' ' && boardGet(board, 'g' + from[1], side) === ' ' && + boardGet(board, 'g' + from[1], other) === ' ' && boardGet(board, 'h' + from[1], side) === 'r') { if (!hasMoved(board, side, 'h' + from[1])) { legals.push('g' + from[1]); } } if (boardGet(board, 'd' + from[1], side) === ' ' && + boardGet(board, 'd' + from[1], other) === ' ' && boardGet(board, 'c' + from[1], side) === ' ' && + boardGet(board, 'c' + from[1], other) === ' ' && boardGet(board, 'b' + from[1], side) === ' ' && + boardGet(board, 'b' + from[1], other) === ' ' && boardGet(board, 'a' + from[1], side) === 'r') { if (!hasMoved(board, side, 'a' + from[1])) { legals.push('c' + from[1]);