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;
|
return;
|
||||||
}
|
}
|
||||||
if (this.isHoldingPiece()) {
|
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) {
|
if (this.makeMove(this.heldPiece(), i) !== 0) {
|
||||||
this.setHand({
|
this.setHand({
|
||||||
heldPiece: null,
|
heldPiece: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return;
|
} else if (this.state.squares[i] != null) {
|
||||||
}
|
|
||||||
if (this.state.squares[i] != null) {
|
|
||||||
let isSquareBlack = isBlack(this.state.squares[i]);
|
let isSquareBlack = isBlack(this.state.squares[i]);
|
||||||
if(isSquareBlack === this.state.blackIsNext) {
|
if(isSquareBlack === this.state.blackIsNext) {
|
||||||
this.setHand({
|
this.setHand({
|
||||||
|
|
Loading…
Reference in New Issue