+ const oppCol = this.getOppCol(color);
+ var potentialMoves = [];
+ let sideBoard = [this.getSideBoard(1), this.getSideBoard(2)];
+ for (var i=0; i<V.size.x; i++)
+ {
+ for (var j=0; j<V.size.y; j++)
+ {
+ if (this.board[i][j] != V.EMPTY && this.getColor(i,j) == color)
+ {
+ const mirrorSide =
+ Object.keys(V.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(V.ALICE_CODES);
+ move.vanish.forEach(psq => {
+ const mirrorSide = (pieces.includes(psq.p) ? 1 : 2);
+ sideBoard[mirrorSide-1][psq.x][psq.y] = V.EMPTY;
+ });
+ move.appear.forEach(psq => {
+ const mirrorSide = (pieces.includes(psq.p) ? 1 : 2);
+ const piece = (mirrorSide == 1 ? psq.p : V.ALICE_PIECES[psq.p]);
+ sideBoard[mirrorSide-1][psq.x][psq.y] = psq.c + piece;
+ if (piece == V.KING)
+ this.kingPos[psq.c] = [psq.x,psq.y];
+ });
+ }
+
+ // Undo on sideboards
+ undoSide(move, sideBoard)
+ {
+ const pieces = Object.keys(V.ALICE_CODES);
+ move.appear.forEach(psq => {
+ const mirrorSide = (pieces.includes(psq.p) ? 1 : 2);
+ sideBoard[mirrorSide-1][psq.x][psq.y] = V.EMPTY;
+ });
+ move.vanish.forEach(psq => {
+ const mirrorSide = (pieces.includes(psq.p) ? 1 : 2);
+ const piece = (mirrorSide == 1 ? psq.p : V.ALICE_PIECES[psq.p]);
+ sideBoard[mirrorSide-1][psq.x][psq.y] = psq.c + piece;
+ if (piece == V.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]] != V.EMPTY ? 1 : 2);