require empty squares (both sides) between king and rook to castle
This commit is contained in:
parent
baf4c19f1d
commit
def7ccdbcb
|
|
@ -161,18 +161,24 @@ function legalMoves(board, side, type, from, canCapture){
|
||||||
scanPath(legals, board, side, from, false, dir[0], dir[1], 0);
|
scanPath(legals, board, side, from, false, dir[0], dir[1], 0);
|
||||||
}
|
}
|
||||||
if (from[0] === 'e' && from[1] === (isDark(side) ? '8' : '1')) {
|
if (from[0] === 'e' && from[1] === (isDark(side) ? '8' : '1')) {
|
||||||
|
const other = otherSide(side);
|
||||||
/* check for castling conditions */
|
/* check for castling conditions */
|
||||||
if (!hasMoved(board, side, from)) {
|
if (!hasMoved(board, side, from)) {
|
||||||
if (boardGet(board, 'f' + from[1], side) === ' ' &&
|
if (boardGet(board, 'f' + from[1], side) === ' ' &&
|
||||||
|
boardGet(board, 'f' + from[1], other) === ' ' &&
|
||||||
boardGet(board, 'g' + from[1], side) === ' ' &&
|
boardGet(board, 'g' + from[1], side) === ' ' &&
|
||||||
|
boardGet(board, 'g' + from[1], other) === ' ' &&
|
||||||
boardGet(board, 'h' + from[1], side) === 'r') {
|
boardGet(board, 'h' + from[1], side) === 'r') {
|
||||||
if (!hasMoved(board, side, 'h' + from[1])) {
|
if (!hasMoved(board, side, 'h' + from[1])) {
|
||||||
legals.push('g' + from[1]);
|
legals.push('g' + from[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (boardGet(board, 'd' + from[1], side) === ' ' &&
|
if (boardGet(board, 'd' + from[1], side) === ' ' &&
|
||||||
|
boardGet(board, 'd' + from[1], other) === ' ' &&
|
||||||
boardGet(board, 'c' + from[1], side) === ' ' &&
|
boardGet(board, 'c' + from[1], side) === ' ' &&
|
||||||
|
boardGet(board, 'c' + from[1], other) === ' ' &&
|
||||||
boardGet(board, 'b' + from[1], side) === ' ' &&
|
boardGet(board, 'b' + from[1], side) === ' ' &&
|
||||||
|
boardGet(board, 'b' + from[1], other) === ' ' &&
|
||||||
boardGet(board, 'a' + from[1], side) === 'r') {
|
boardGet(board, 'a' + from[1], side) === 'r') {
|
||||||
if (!hasMoved(board, side, 'a' + from[1])) {
|
if (!hasMoved(board, side, 'a' + from[1])) {
|
||||||
legals.push('c' + from[1]);
|
legals.push('c' + from[1]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue