- isAttacked(sq, colors)
- {
- if (this.getPiece(sq[0],sq[1]) == V.KING && this.isAttackedByKing(sq, colors))
- return false; //king cannot take...
- return (this.isAttackedByPawn(sq, colors)
- || this.isAttackedByRook(sq, colors)
- || this.isAttackedByKnight(sq, colors)
- || this.isAttackedByBishop(sq, colors)
- || this.isAttackedByQueen(sq, colors));
+ isAttacked(sq, color) {
+ if (
+ this.getPiece(sq[0], sq[1]) == V.KING &&
+ this.isAttackedByKing(sq, color)
+ ) {
+ // A king next to the enemy king is immune to attacks
+ return false;
+ }
+ return (
+ this.isAttackedByPawn(sq, color) ||
+ this.isAttackedByRook(sq, color) ||
+ this.isAttackedByKnight(sq, color) ||
+ this.isAttackedByBishop(sq, color) ||
+ this.isAttackedByQueen(sq, color)
+ // No "attackedByKing": it cannot take
+ );