- getBasicMove([x1, y1], [x2, y2], tr) {
- // Apply mushroom, bomb or banana effect (hidden to the player).
- // Determine egg effect, too, and apply its first part if possible.
- let move = super.getBasicMove([x1, y1], [x2, y2], tr);
- const color1 = this.getColor(x1, y1);
- const color2 = this.getColor(x2, y2);
- const piece1 = this.getPiece(x1, y1);
- const piece2 = this.getPiece(x2, y2);
+ canMove([x, y], piece) {
+ const color = this.getColor(x, y);
+ const oppCol = V.GetOppCol(color);
+ piece = piece || this.getPiece(x, y);
+ if (piece == V.PAWN) {
+ const forward = (color == 'w' ? -1 : 1);
+ return (
+ V.OnBoard(x + forward, y) &&
+ (
+ this.board[x + forward][y] != oppCol ||
+ (
+ V.OnBoard(x + forward, y + 1) &&
+ this.board[x + forward][y + 1] != V.EMPTY &&
+ this.getColor[x + forward, y + 1] == oppCol
+ ) ||
+ (
+ V.OnBoard(x + forward, y - 1) &&
+ this.board[x + forward][y - 1] != V.EMPTY &&
+ this.getColor[x + forward, y - 1] == oppCol
+ )
+ )
+ );
+ }
+ // Checking one step is enough:
+ const steps =
+ [V.KING, V.QUEEN].includes(piece)
+ ? V.steps[V.ROOK].concat(V.steps[V.BISHOP])
+ : V.steps[piece];
+ for (let step of steps) {
+ const [i, j] = [x + step[0], y + step[1]];
+ if (
+ V.OnBoard(i, j) &&
+ (this.board[i][j] == V.EMPTY || this.getColor(i, j) != color)
+ ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // Apply mushroom, bomb or banana effect (hidden to the player).
+ // Determine egg effect, too, and apply its first part if possible.
+ getBasicMove_aux(psq1, sq2, tr, initMove) {
+ const [x1, y1] = [psq1.x, psq1.y];
+ const color1 = this.turn;
+ const piece1 = (!!tr ? tr.p : (psq1.p || this.getPiece(x1, y1)));