From 01b20c4f22ef463dec8262498848d3f7236b34ef Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 9 Feb 2018 19:12:20 +0100 Subject: [PATCH] Fix a Chess.js issue when the king started on the c- or g-files. --- www/js/chess.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/www/js/chess.js b/www/js/chess.js index 569d7c8..6d6623e 100644 --- a/www/js/chess.js +++ b/www/js/chess.js @@ -968,11 +968,12 @@ var Chess = function(fen) { function make_move(move) { var us = turn; var them = swap_color(us); - var old_to = board[move.to]; push(move); board[move.to] = board[move.from]; - board[move.from] = null; + if (move.from != move.to) { + board[move.from] = null; + } /* if ep capture, remove the captured pawn */ if (move.flags & BITS.EP_CAPTURE) { @@ -996,13 +997,13 @@ var Chess = function(fen) { if (move.flags & BITS.KSIDE_CASTLE) { var castling_to = move.to - 1; var castling_from = move.rook_sq; - board[castling_to] = old_to===null ? board[castling_from] : old_to; + board[castling_to] = board[castling_from]; if(castling_from !== move.to) board[castling_from] = null; } else if (move.flags & BITS.QSIDE_CASTLE) { var castling_to = move.to + 1; var castling_from = move.rook_sq; - board[castling_to] = old_to===null ? board[castling_from] : old_to; + board[castling_to] = board[castling_from]; if(castling_from !== move.to) board[castling_from] = null; } @@ -1074,11 +1075,11 @@ var Chess = function(fen) { var us = turn; var them = swap_color(turn); - var old_from = board[move.from]; - - board[move.from] = board[move.to]; - board[move.from].type = move.piece; // to undo any promotions - board[move.to] = null; + if (move.from != move.to) { + board[move.from] = board[move.to]; + board[move.from].type = move.piece; // to undo any promotions + board[move.to] = null; + } if (move.flags & BITS.CAPTURE) { board[move.to] = {type: move.captured, color: them}; @@ -1103,7 +1104,7 @@ var Chess = function(fen) { castling_from = move.to + 1; } - board[castling_to] = old_from===null ? board[castling_from] : old_from; + board[castling_to] = board[castling_from]; if(castling_from !== move.from) board[castling_from] = null; } -- 2.39.2