- return (this.isAttackedByPawn(sq, color)
- || this.isAttackedByRook(sq, color)
- || this.isAttackedByKnight(sq, color)
- || this.isAttackedByBishop(sq, color)
- || this.isAttackedByQueen(sq, color)
- || this.isAttackedByKing(sq, color));
+ const color = this.turn;
+ const oppCol = this.getOppCol(color);
+ let [sizeX,sizeY] = VariantRules.size;
+ for (let i=0; i<sizeX; i++)
+ {
+ for (let j=0; j<sizeY; j++)
+ {
+ if (this.board[i][j] != VariantRules.EMPTY && this.getColor(i,j) != oppCol)
+ {
+ const moves = this.getPotentialMovesFrom([i,j]);
+ if (moves.length > 0)
+ {
+ for (let k=0; k<moves.length; k++)
+ {
+ if (this.filterValid([moves[k]]).length > 0)
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ // Check if pieces of color 'colors' are attacking square x,y
+ isAttacked(sq, colors)
+ {
+ return (this.isAttackedByPawn(sq, colors)
+ || this.isAttackedByRook(sq, colors)
+ || this.isAttackedByKnight(sq, colors)
+ || this.isAttackedByBishop(sq, colors)
+ || this.isAttackedByQueen(sq, colors)
+ || this.isAttackedByKing(sq, colors));