Skip to content

Commit

Permalink
fix: changing piece on the kings square with chess.put() (#426)
Browse files Browse the repository at this point in the history
* fix: changing piece on the kings square with chess.put()
  • Loading branch information
Manukyanq authored Jul 21, 2023
1 parent 2dcfad2 commit 6ff1821
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/chess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6ff1821

Please sign in to comment.