+ getAllPotentialMoves() {
+ const color = this.turn;
+ const oppCol = V.GetOppCol(color);
+ let potentialMoves = [];
+ for (let i = 0; i < V.size.x; i++) {
+ for (let j = 0; j < V.size.y; j++) {
+ const colIJ = this.getColor(i, j);
+ if (
+ this.board[i][j] != V.EMPTY &&
+ (
+ (this.stage == 1 && colIJ != oppCol) ||
+ (this.stage == 2 &&
+ (
+ (this.sideCheckered == color && colIJ == 'c') ||
+ (this.sideCheckered != color && ['w', 'b'].includes(colIJ))
+ )
+ )
+ )
+ ) {
+ Array.prototype.push.apply(
+ potentialMoves,
+ this.getPotentialMovesFrom([i, j])
+ );
+ }
+ }
+ }
+ return potentialMoves;
+ }
+
+ atLeastOneMove() {
+ const color = this.turn;
+ const oppCol = V.GetOppCol(color);
+ for (let i = 0; i < V.size.x; i++) {
+ for (let j = 0; j < V.size.y; j++) {
+ const colIJ = this.getColor(i, j);
+ if (
+ this.board[i][j] != V.EMPTY &&
+ (
+ (this.stage == 1 && colIJ != oppCol) ||
+ (this.stage == 2 &&
+ (
+ (this.sideCheckered == color && colIJ == 'c') ||
+ (this.sideCheckered != color && ['w', 'b'].includes(colIJ))
+ )
+ )
+ )
+ ) {
+ const moves = this.getPotentialMovesFrom([i, j], "noswitch");
+ if (moves.length > 0) {
+ for (let k = 0; k < moves.length; k++)
+ if (this.filterValid([moves[k]]).length > 0) return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ // colors: array, 'w' and 'c' or 'b' and 'c' at stage 1,
+ // just 'c' (or unused) at stage 2
+ isAttacked(sq, colors) {
+ if (!Array.isArray(colors)) colors = [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)
+ );
+ }
+