fix for castling broken by fix for swapped king and queen

This commit is contained in:
Jesse D. McDonald 2020-03-13 02:00:29 -05:00
parent 5286e9e18f
commit 1f754f53a3
1 changed files with 18 additions and 18 deletions

View File

@ -155,22 +155,22 @@ function legalMoves(board, side, type, from, canCapture){
for (const dir of ortho.concat(diag)) {
scanPath(legals, board, side, from, false, dir[0], dir[1], 0);
}
if (from[0] === 'd' && from[1] === (isDark(side) ? '8' : '1')) {
if (from[0] === 'e' && from[1] === (isDark(side) ? '8' : '1')) {
/* check for castling conditions */
if (!hasMoved(board, side, from)) {
if (boardGet(board, 'c' + from[1], side) === ' ' &&
boardGet(board, 'b' + from[1], side) === ' ' &&
boardGet(board, 'a' + from[1], side) === 'r') {
if (!hasMoved(board, side, 'a' + from[1])) {
legals.push('b' + from[1]);
}
}
if (boardGet(board, 'e' + from[1], side) === ' ' &&
boardGet(board, 'f' + from[1], side) === ' ' &&
if (boardGet(board, 'f' + from[1], side) === ' ' &&
boardGet(board, 'g' + from[1], side) === ' ' &&
boardGet(board, 'h' + from[1], side) === 'r') {
if (!hasMoved(board, side, 'h' + from[1])) {
legals.push('f' + from[1]);
legals.push('g' + from[1]);
}
}
if (boardGet(board, 'd' + from[1], side) === ' ' &&
boardGet(board, 'c' + from[1], side) === ' ' &&
boardGet(board, 'b' + from[1], side) === ' ' &&
boardGet(board, 'a' + from[1], side) === 'r') {
if (!hasMoved(board, side, 'a' + from[1])) {
legals.push('c' + from[1]);
}
}
}
@ -283,15 +283,15 @@ function movePiece(priorBoard, side, from, to){
if (alongside !== ' ') {
board['move']['alongside'] = alongside;
}
if (type === 'k' && actuallyFrom[0] === 'd' && to[0] === 'b') {
if (type === 'k' && actuallyFrom[0] === 'e' && to[0] === 'g') {
board['move']['castle'] = true;
boardPut(board, 'a' + actuallyFrom[1], side, ' ');
boardPut(board, 'c' + actuallyFrom[1], side, 'r');
}
if (type === 'k' && actuallyFrom[0] === 'd' && to[0] === 'f') {
board['move']['queen_castle'] = true;
boardPut(board, 'h' + actuallyFrom[1], side, ' ');
boardPut(board, 'e' + actuallyFrom[1], side, 'r');
boardPut(board, 'f' + actuallyFrom[1], side, 'r');
}
if (type === 'k' && actuallyFrom[0] === 'e' && to[0] === 'c') {
board['move']['queen_castle'] = true;
boardPut(board, 'a' + actuallyFrom[1], side, ' ');
boardPut(board, 'd' + actuallyFrom[1], side, 'r');
}
if (type === 'p' && (isDark(side) ? (to[1] === '1') : (to[1] === '8'))) {
board['move']['promotion'] = 'q'; /* TODO: allow other choices */