@chess-fu/chess-game
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -656,5 +656,20 @@ "use strict"; | ||
var isLegal = false; | ||
var targetIx = chessUtils_1.offsetToIndex(move); | ||
var restore = [targetIx, this._board[targetIx], squareIx, this._board[squareIx]]; | ||
this._board[squareIx] = constants_1.NONE; | ||
var targetIx = chessUtils_1.offsetToIndex(move); | ||
var saved = this._board[targetIx]; | ||
if (this._enpass >= 0 && move.enpass) { | ||
var killSquare = chessUtils_1.offsetToIndex({ y: move.y === 2 ? move.y + 1 : move.y - 1, x: move.x }); | ||
restore.push(killSquare, this._board[killSquare]); | ||
this._board[killSquare] = constants_1.NONE; | ||
} | ||
else if (move.castle && move.castle in INDEXES) { | ||
var castleIx = INDEXES[move.castle]; | ||
var rookPiece = (this._turn === constants_1.WHITE ? constants_1.ROOK.toUpperCase() : constants_1.ROOK); | ||
var queenSide = move.castle < move.from; | ||
var rookToIx = targetIx + (queenSide ? 1 : -1); | ||
restore.push(castleIx, this._board[castleIx]); | ||
restore.push(rookToIx, this._board[rookToIx]); | ||
this._board[castleIx] = constants_1.NONE; | ||
this._board[rookToIx] = rookPiece; | ||
} | ||
try { | ||
@@ -679,4 +694,5 @@ this._board[targetIx] = movingPiece; | ||
finally { | ||
this._board[targetIx] = saved; | ||
this._board[squareIx] = movingPiece; | ||
for (var ix = 0; ix < restore.length; ix += 2) { | ||
this._board[restore[ix]] = restore[ix + 1]; | ||
} | ||
this._whiteKing = _whiteKing; | ||
@@ -683,0 +699,0 @@ this._blackKing = _blackKing; |
{ | ||
"name": "@chess-fu/chess-game", | ||
"access": "public", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Chess game logic", | ||
@@ -6,0 +6,0 @@ "author": "chess-fu.com", |
50240
1147