]> git.sesse.net Git - remoteglot/blobdiff - www/js/chess.js
Fix Chess960 bug when castling does not move the rook.
[remoteglot] / www / js / chess.js
index 6d6623e4d90005e7b5616346ca920391a4963d17..9da372c9d920526f9802dc8fa63a9c0bed97c35f 100644 (file)
@@ -997,14 +997,14 @@ 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] = board[castling_from];
-        if(castling_from !== move.to)
+        board[castling_to] = {type: ROOK, color: us};
+        if(castling_from !== move.to && castling_from !== castling_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] = board[castling_from];
-        if(castling_from !== move.to)
+        board[castling_to] = {type: ROOK, color: us};
+        if(castling_from !== move.to && castling_from !== castling_to)
           board[castling_from] = null;
       }
 
@@ -1105,7 +1105,7 @@ var Chess = function(fen) {
       }
 
       board[castling_to] = board[castling_from];
-      if(castling_from !== move.from)
+      if(castling_from !== move.from && castling_from !== castling_to)
         board[castling_from] = null;
     }