+ // En passant: always OK if subturn 1,
+ // OK on subturn 2 only if enPassant was played at subturn 1
+ // (and if there are two e.p. squares available).
+ const Lep = this.epSquares.length;
+ const epSquares = this.epSquares[Lep - 1]; //always at least one element
+ let epSqs = [];
+ epSquares.forEach(sq => {
+ if (sq) epSqs.push(sq);
+ });
+ if (epSqs.length == 0) return moves;
+ const oppCol = V.GetOppCol(color);
+ for (let sq of epSqs) {
+ if (
+ this.subTurn == 1 ||
+ (epSqs.length == 2 &&
+ // Was this en-passant capture already played at subturn 1 ?
+ // (Or maybe the opponent filled the en-passant square with a piece)
+ this.board[epSqs[0].x][epSqs[0].y] != V.EMPTY)
+ ) {
+ if (
+ sq.x == x + shiftX &&
+ Math.abs(sq.y - y) == 1 &&
+ // Add condition "enemy pawn must be present"
+ this.getPiece(x, sq.y) == V.PAWN &&
+ this.getColor(x, sq.y) == oppCol
+ ) {
+ let epMove = this.getBasicMove([x, y], [sq.x, sq.y]);
+ epMove.vanish.push({
+ x: x,
+ y: sq.y,
+ p: "p",
+ c: oppCol
+ });
+ moves.push(epMove);
+ }
+ }
+ }