- moves.push(this.getBasicMove([x,y], [x+shift,y+1]));
- }
- }
-
- if (x+shift == lastRank)
- {
- // Promotion
- const pawnColor = this.getColor(x,y); //can be different for checkered
- 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:pawnColor,p:p}));
- // Captures
- if (y>0 && this.board[x+shift][y-1] != V.EMPTY
- && this.canTake([x,y], [x+shift,y-1]))
- {
- moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:pawnColor,p:p}));
- }
- if (y<sizeY-1 && this.board[x+shift][y+1] != V.EMPTY
- && this.canTake([x,y], [x+shift,y+1]))
+ if (y + shiftY >= 0 && y + shiftY < sizeY
+ && this.board[x+shiftX][y+shiftY] != V.EMPTY
+ && this.canTake([x,y], [x+shiftX,y+shiftY]))