From 6ff18217bdaf5a60585bd38d7afb682e7ad65f2a Mon Sep 17 00:00:00 2001 From: Artsvi Manukyan <42891870+Manukyanq@users.noreply.github.com> Date: Fri, 21 Jul 2023 19:58:35 +0300 Subject: [PATCH] fix: changing piece on the kings square with chess.put() (#426) * fix: changing piece on the kings square with chess.put() --- src/chess.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/chess.ts b/src/chess.ts index 2058d4c5..647f4d07 100644 --- a/src/chess.ts +++ b/src/chess.ts @@ -806,6 +806,13 @@ export class Chess { return false } + const currentPieceOnSquare = this._board[sq] + + // if one of the kings will be replaced by the piece from args, set the `_kings` respective entry to `EMPTY` + if (currentPieceOnSquare && currentPieceOnSquare.type === KING) { + this._kings[currentPieceOnSquare.color] = EMPTY + } + this._board[sq] = { type: type as PieceSymbol, color: color as Color } if (type === KING) {