+ return res;
+ }
+
+ // NOTE: alternative implementation, recompute sideBoard's in this function
+ filterValid(moves, sideBoard)
+ {
+ if (moves.length == 0)
+ return [];
+ const pieces = Object.keys(VariantRules.ALICE_CODES);
+ return moves.filter(m => {
+ // WARNING: for underCheck(), we need the sideBoard of the arrival world !
+ const mirrorSide = (pieces.includes(this.getPiece(m.start.x,m.start.y)) ? 2 : 1);
+ return !this.underCheck(m, !!sideBoard ? sideBoard[mirrorSide-1] : null);
+ });
+ }
+
+ getAllValidMoves()
+ {
+ const color = this.turn;
+ 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);