+ const color = this.turn;
+ let moves = [];
+ const V = VariantRules;
+ const [sizeX,sizeY] = VariantRules.size;
+ const shift = (color == "w" ? -1 : 1);
+ const startRanks = (color == "w" ? [sizeY-2,sizeY-3] : [1,2]);
+ const lastRanks = (color == "w" ? [0,1,2] : [sizeY-1,sizeY-2,sizeY-3]);
+
+ if (x+shift >= 0 && x+shift < sizeX && x+shift != lastRanks[0])
+ {
+ // Normal moves
+ if (this.board[x+shift][y] == V.EMPTY)
+ {
+ moves.push(this.getBasicMove([x,y], [x+shift,y]));
+ if (startRanks.includes(x) && this.board[x+2*shift][y] == V.EMPTY)
+ {
+ // Two squares jump
+ moves.push(this.getBasicMove([x,y], [x+2*shift,y]));
+ if (x == startRanks[0] && this.board[x+2*shift][y] == V.EMPTY)
+ {
+ // 3-squares jump
+ moves.push(this.getBasicMove([x,y], [x+3*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 (lastRanks.includes(x+shift))
+ {
+ // Promotion
+ let promotionPieces = [V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN];
+ promotionPieces.forEach(p => {
+ if (!this.captures[color][p] || this.captures[color][p]==0)
+ return;
+ // 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}));
+ });
+ }
+
+ // En passant
+ const Lep = this.epSquares.length;
+ const epSquare = Lep>0 ? this.epSquares[Lep-1] : undefined;
+ if (!!epSquare)
+ {
+ for (let epsq of epSquare)
+ {
+ // TODO: some redundant checks
+ if (epsq.x == x+shift && Math.abs(epsq.y - y) == 1)
+ {
+ let epStep = epsq.y - y;
+ var enpassantMove = this.getBasicMove([x,y], [x+shift,y+epStep]);
+ enpassantMove.vanish.push({
+ x: x,
+ y: y+epStep,
+ p: 'p',
+ c: this.getColor(x,y+epStep)
+ });
+ moves.push(enpassantMove);
+ }
+ }
+ }
+
+ return moves;