+ const oppCol = this.getOppCol(color);
+ var potentialMoves = [];
+ let [sizeX,sizeY] = VariantRules.size;
+ let sideBoard = [this.getSideBoard(1), this.getSideBoard(2)];
+ for (var i=0; i<sizeX; i++)
+ {
+ for (var j=0; j<sizeY; j++)
+ {
+ if (this.board[i][j] != VariantRules.EMPTY && this.getColor(i,j) == color)
+ {
+ const mirrorSide =
+ (Object.keys(VariantRules.ALICE_CODES).includes(this.getPiece(i,j)) ? 1 : 2);
+ Array.prototype.push.apply(potentialMoves,
+ this.getPotentialMovesFrom([i,j], sideBoard[mirrorSide-1]));
+ }
+ }
+ }
+ return this.filterValid(potentialMoves, sideBoard);
+ }
+
+ // Play on sideboards [TODO: only one sideBoard required]
+ playSide(move, sideBoard)
+ {
+ const pieces = Object.keys(VariantRules.ALICE_CODES);
+ move.vanish.forEach(psq => {
+ const mirrorSide = (pieces.includes(psq.p) ? 1 : 2);
+ sideBoard[mirrorSide-1][psq.x][psq.y] = VariantRules.EMPTY;
+ });
+ move.appear.forEach(psq => {
+ const mirrorSide = (pieces.includes(psq.p) ? 1 : 2);
+ const piece = (mirrorSide == 1 ? psq.p : VariantRules.ALICE_PIECES[psq.p]);
+ sideBoard[mirrorSide-1][psq.x][psq.y] = psq.c + piece;
+ if (piece == VariantRules.KING)
+ this.kingPos[psq.c] = [psq.x,psq.y];
+ });
+ }
+
+ // Undo on sideboards
+ undoSide(move, sideBoard)
+ {
+ const pieces = Object.keys(VariantRules.ALICE_CODES);
+ move.appear.forEach(psq => {
+ const mirrorSide = (pieces.includes(psq.p) ? 1 : 2);
+ sideBoard[mirrorSide-1][psq.x][psq.y] = VariantRules.EMPTY;
+ });
+ move.vanish.forEach(psq => {
+ const mirrorSide = (pieces.includes(psq.p) ? 1 : 2);
+ const piece = (mirrorSide == 1 ? psq.p : VariantRules.ALICE_PIECES[psq.p]);
+ sideBoard[mirrorSide-1][psq.x][psq.y] = psq.c + piece;
+ if (piece == VariantRules.KING)
+ this.kingPos[psq.c] = [psq.x,psq.y];
+ });
+ }
+
+ underCheck(move, sideBoard) //sideBoard arg always provided
+ {
+ const color = this.turn;
+ this.playSide(move, sideBoard); //no need to track flags
+ const kp = this.kingPos[color];
+ const mirrorSide = sideBoard[0][kp[0]][kp[1]] != VariantRules.EMPTY ? 1 : 2;