- }
-
- // TODO: when pawn is pushed to 8th rank, apply promotions (similar change as in Checkered)
- getBasicMove([sx,sy], [ex,ey], tr)
- {
- var mv = new Move({
- appear: [
- new PiPo({
- x: ex,
- y: ey,
- c: !!tr ? tr.c : this.getColor(sx,sy),
- p: !!tr ? tr.p : this.getPiece(sx,sy)
- })
- ],
- vanish: [
- new PiPo({
- x: sx,
- y: sy,
- c: this.getColor(sx,sy),
- p: this.getPiece(sx,sy)
- })
- ]
- });
-
- if (this.board[ex][ey] != VariantRules.EMPTY)
- {
- mv.vanish.push(
- new PiPo({
- x: ex,
- y: ey,
- c: this.getColor(ex,ey),
- p: this.getPiece(ex,ey)
- })
- );
- }
- this.applyMagneticLaws([ex,ey], mv);
- return mv;
- }
-
- getPotentialPawnMoves([x,y])
- {
- const color = this.getColor(x,y);
- var moves = [];
- var V = VariantRules;
- const [sizeX,sizeY] = VariantRules.size;
- let shift = (color == "w" ? -1 : 1);
- let startRank = (color == "w" ? sizeY-2 : 1);
- let firstRank = (color == 'w' ? sizeY-1 : 0);
- let lastRank = (color == "w" ? 0 : sizeY-1);
-
- if (x+shift >= 0 && x+shift < sizeX && x+shift != lastRank)
- {
- // Normal moves
- if (this.board[x+shift][y] == V.EMPTY)
- {
- moves.push(this.getBasicMove([x,y], [x+shift,y]));
- if ([startRank,firstRank].includes(x) && this.board[x+2*shift][y] == V.EMPTY)
- {
- // Two squares jump
- moves.push(this.getBasicMove([x,y], [x+2*shift,y]));
- }
- }
- // Captures
- if (y>0 && this.canTake([x,y], [x+shift,y-1]) && this.board[x+shift][y-1] != V.EMPTY)
- moves.push(this.getBasicMove([x,y], [x+shift,y-1]));
- if (y<sizeY-1 && this.canTake([x,y], [x+shift,y+1]) && this.board[x+shift][y+1] != V.EMPTY)
- moves.push(this.getBasicMove([x,y], [x+shift,y+1]));
- }
-
- if (x+shift == lastRank)
- {
- // Promotion
- let promotionPieces = [V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN];
- promotionPieces.forEach(p => {
- // Normal move
- if (this.board[x+shift][y] == V.EMPTY)
- moves.push(this.getBasicMove([x,y], [x+shift,y], {c:color,p:p}));
- // Captures
- if (y>0 && this.canTake([x,y], [x+shift,y-1]) && this.board[x+shift][y-1] != V.EMPTY)
- moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:color,p:p}));
- if (y<sizeY-1 && this.canTake([x,y], [x+shift,y+1]) && this.board[x+shift][y+1] != V.EMPTY)
- moves.push(this.getBasicMove([x,y], [x+shift,y+1], {c:color,p:p}));
- });
- }
-
- // No en passant
-
- return moves;
- }
-
- getCastleMoves([x,y])
- {
- const c = this.getColor(x,y);
- if (x != (c=="w" ? 7 : 0) || y != this.INIT_COL_KING[c])
- return []; //x isn't first rank, or king has moved (shortcut)
-
- const V = VariantRules;
-
- // Castling ?
- const oppCol = this.getOppCol(c);