+ 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;
+ }
+