- // sideBoard: arg containing both boards (see getAllValidMoves())
- underCheck(color, sideBoard)
- {
- const kp = this.kingPos[color];
- const mirrorSide = (sideBoard[0][kp[0]][kp[1]] != V.EMPTY ? 1 : 2);
- let saveBoard = this.board;
- this.board = sideBoard[mirrorSide-1];
- let res = this.isAttacked(kp, [V.GetOppCol(color)]);
- this.board = saveBoard;
- return res;
- }
+ getAllValidMoves() {
+ const color = this.turn;
+ let potentialMoves = [];
+ const 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) {
+ Array.prototype.push.apply(
+ potentialMoves,
+ this.getPotentialMovesFrom([i, j], sideBoard)
+ );
+ }
+ }
+ }
+ 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];
+ });
+ }