diff --git a/src/index.js b/src/index.js index b5f31ba..07ff761 100644 --- a/src/index.js +++ b/src/index.js @@ -440,14 +440,23 @@ class Board extends React.Component { return; } if (this.isHoldingPiece()) { + // Copy the board + var board = new Board(); + board.state.squares = this.state.squares.slice(); + board.state.squares[i] = board.state.squares[this.heldPiece()]; + board.state.squares[this.heldPiece()] = null; + + let moversKing = this.state.blackIsNext ? + new Piece(BLACK, KING) : new Piece(WHITE, KING); + if (board.inCheck(moversKing) != null) { + return; + } if (this.makeMove(this.heldPiece(), i) !== 0) { this.setHand({ heldPiece: null, }); } - return; - } - if (this.state.squares[i] != null) { + } else if (this.state.squares[i] != null) { let isSquareBlack = isBlack(this.state.squares[i]); if(isSquareBlack === this.state.blackIsNext) { this.setHand({