Ban moving self into, or staying in check
This commit is contained in:
parent
51efbdfd4e
commit
6ca3a810c6
15
src/index.js
15
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({
|
||||
|
|
Loading…
Reference in New Issue