-export const VariantRules = class BerolinaRules extends ChessRules
-{
- // En-passant after 2-sq jump
- getEpSquare(moveOrSquare)
- {
- if (!moveOrSquare)
- return undefined;
- if (typeof moveOrSquare === "string")
- {
- const square = moveOrSquare;
- if (square == "-")
- return undefined;
- // Enemy pawn initial column must be given too:
- let res = [];
- const epParts = square.split(",");
- res.push(V.SquareToCoords(epParts[0]));
- res.push(V.ColumnToCoord(epParts[1]));
- return res;
- }
- // Argument is a move:
- const move = moveOrSquare;
- const [sx,ex,sy] = [move.start.x,move.end.x,move.start.y];
- if (this.getPiece(sx,sy) == V.PAWN && Math.abs(sx - ex) == 2)
- {
- return
- [
- {
- x: (ex + sx)/2,
- y: (move.end.y + sy)/2
- },
- move.end.y
- ];
- }
- return undefined; //default
- }
+export class BerolinaRules extends ChessRules {
+ // En-passant after 2-sq jump
+ getEpSquare(moveOrSquare) {
+ if (!moveOrSquare) return undefined;
+ if (typeof moveOrSquare === "string") {
+ const square = moveOrSquare;
+ if (square == "-") return undefined;
+ // Enemy pawn initial column must be given too:
+ let res = [];
+ const epParts = square.split(",");
+ res.push(V.SquareToCoords(epParts[0]));
+ res.push(V.ColumnToCoord(epParts[1]));
+ return res;
+ }
+ // Argument is a move:
+ const move = moveOrSquare;
+ const [sx, ex, sy] = [move.start.x, move.end.x, move.start.y];
+ if (this.getPiece(sx, sy) == V.PAWN && Math.abs(sx - ex) == 2) {
+ return [
+ {
+ x: (ex + sx) / 2,
+ y: (move.end.y + sy) / 2
+ },
+ // The arrival column must be remembered, because
+ // potentially two pawns could be candidates to be captured:
+ // one on our left, and one on our right.
+ move.end.y
+ ];
+ }
+ return undefined; //default
+ }