- var moves = [];
- var V = VariantRules;
- let [sizeX,sizeY] = VariantRules.size;
- const c = (color == 'c' ? this.turn : color);
- const shift = (c == "w" ? -1 : 1);
- let startRank = (c == "w" ? sizeY-2 : 1);
- let lastRank = (c == "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)[0]);
- if (x==startRank && this.board[x+2*shift][y] == V.EMPTY && this.flags[1][c][y])
- {
- // Two squares jump
- moves.push(this.getBasicMove(x, y, x+2*shift, y)[0]);
- }
- }
- // Captures
- if (y>0 && this.canTake(this.getColor(x,y), this.getColor(x+shift,y-1))
- && this.board[x+shift][y-1] != V.EMPTY)
- {
- moves = moves.concat(this.getBasicMove(x, y, x+shift, y-1));
- }
- if (y<sizeY-1 && this.canTake(this.getColor(x,y), this.getColor(x+shift,y+1))
- && this.board[x+shift][y+1] != V.EMPTY)
- {
- moves = moves.concat(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, p)[0]);
- // Captures
- if (y>0 && this.canTake(this.getColor(x,y), this.getColor(x+shift,y-1))
- && this.board[x+shift][y-1] != V.EMPTY)
- {
- moves = moves.concat(this.getBasicMove(x, y, x+shift, y-1, p));
- }
- if (y<sizeY-1 && this.canTake(this.getColor(x,y), this.getColor(x+shift,y+1))
- && this.board[x+shift][y+1] != V.EMPTY)
- {
- moves = moves.concat(this.getBasicMove(x, y, x+shift, y+1, p));
- }
- });
- }
-
- // En passant
- const Lep = this.epSquares.length;
- const epSquare = Lep>0 ? this.epSquares[Lep-1] : undefined;
- if (!!epSquare && epSquare.x == x+shift && Math.abs(epSquare.y - y) == 1)
- {
- let epStep = epSquare.y - y;
- var enpassantMove = this.getBasicMove(x, y, x+shift, y+epStep)[0];
- enpassantMove.vanish.push({
- x: x,
- y: y+epStep,
- p: 'p',
- c: this.getColor(x,y+epStep)
- });
- enpassantMove.appear[0].c = 'c';
- moves.push(enpassantMove);
- }
-
- return moves;