Ban moving self into, or staying in check

This commit is contained in:
Sage Vaillancourt 2020-12-30 00:09:02 -05:00
parent 51efbdfd4e
commit 6ca3a810c6
1 changed files with 12 additions and 3 deletions

View File

@ -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({