1 class BerolinaRules
extends ChessRules
3 // En-passant after 2-sq jump
4 getEpSquare(moveOrSquare
)
8 if (typeof moveOrSquare
=== "string")
10 const square
= moveOrSquare
;
13 return V
.SquareToCoords(square
);
15 // Argument is a move:
16 const move = moveOrSquare
;
17 const [sx
,ex
,sy
] = [move.start
.x
,move.end
.x
,move.start
.y
];
18 if (this.getPiece(sx
,sy
) == V
.PAWN
&& Math
.abs(sx
- ex
) == 2)
22 y: (move.end
.y
+ sy
)/2
25 return undefined; //default
28 // Special pawn rules: promotions to captured friendly pieces,
29 // optional on ranks 8-9 and mandatory on rank 10.
30 getPotentialPawnMoves([x
,y
])
32 const color
= this.turn
;
34 const [sizeX
,sizeY
] = [V
.size
.x
,V
.size
.y
];
35 const shiftX
= (color
== "w" ? -1 : 1);
36 const firstRank
= (color
== 'w' ? sizeX
-1 : 0);
37 const startRank
= (color
== "w" ? sizeX
-2 : 1);
38 const lastRank
= (color
== "w" ? 0 : sizeX
-1);
40 if (x
+shiftX
>= 0 && x
+shiftX
< sizeX
) //TODO: always true
42 const finalPieces
= x
+ shiftX
== lastRank
43 ? [V
.ROOK
,V
.KNIGHT
,V
.BISHOP
,V
.QUEEN
]
45 // One square diagonally
46 for (let shiftY
of [-1,1])
48 if (this.board
[x
+shiftX
][y
+shiftY
] == V
.EMPTY
)
50 for (let piece
of finalPieces
)
52 moves
.push(this.getBasicMove([x
,y
], [x
+shiftX
,y
+shiftY
],
53 {c:pawnColor
,p:piece
}));
55 if (x
== startRank
&& this.board
[x
+2*shiftX
][y
] == V
.EMPTY
)
58 moves
.push(this.getBasicMove([x
,y
], [x
+2*shiftX
,y
+2*shiftY
]);
63 if (this.board
[x
+shiftX
][y
] != V
.EMPTY
64 && this.canTake([x
,y
], [x
+shiftX
,y
]))
66 for (let piece
of finalPieces
)
68 moves
.push(this.getBasicMove([x
,y
], [x
+shiftX
,y
+shiftY
],
69 {c:pawnColor
,p:piece
}));
75 const Lep
= this.epSquares
.length
;
76 const epSquare
= this.epSquares
[Lep
-1]; //always at least one element
77 if (!!epSquare
&& epSquare
.x
== x
+shiftX
&& epSquare
.y
== y
)
79 let enpassantMove
= this.getBasicMove([x
,y
], [x
+shift
,y
]);
80 enpassantMove
.vanish
.push({
84 c: this.getColor(epSquare
.x
,y
)
86 moves
.push(enpassantMove
);
93 const VariantRules
= BerolinaRules
;