dc9e25740f622be88c720a4ec53c4a6cc1eff395
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 pawns movements
29 getPotentialPawnMoves([x
,y
])
31 const color
= this.turn
;
33 const [sizeX
,sizeY
] = [V
.size
.x
,V
.size
.y
];
34 const shiftX
= (color
== "w" ? -1 : 1);
35 const firstRank
= (color
== 'w' ? sizeX
-1 : 0);
36 const startRank
= (color
== "w" ? sizeX
-2 : 1);
37 const lastRank
= (color
== "w" ? 0 : sizeX
-1);
39 if (x
+shiftX
>= 0 && x
+shiftX
< sizeX
) //TODO: always true
41 const finalPieces
= x
+ shiftX
== lastRank
42 ? [V
.ROOK
,V
.KNIGHT
,V
.BISHOP
,V
.QUEEN
]
44 // One square diagonally
45 for (let shiftY
of [-1,1])
47 if (this.board
[x
+shiftX
][y
+shiftY
] == V
.EMPTY
)
49 for (let piece
of finalPieces
)
50 moves
.push(this.getBasicMove([x
,y
], [x
+shiftX
,y
+shiftY
], {c:color
,p:piece
}));
51 if (x
== startRank
&& y
+2*shiftY
>=0 && y
+2*shiftY
<sizeY
52 && this.board
[x
+2*shiftX
][y
+2*shiftY
] == V
.EMPTY
)
55 moves
.push(this.getBasicMove([x
,y
], [x
+2*shiftX
,y
+2*shiftY
]));
60 if (this.board
[x
+shiftX
][y
] != V
.EMPTY
61 && this.canTake([x
,y
], [x
+shiftX
,y
]))
63 for (let piece
of finalPieces
)
64 moves
.push(this.getBasicMove([x
,y
], [x
+shiftX
,y
], {c:color
,p:piece
}));
69 const Lep
= this.epSquares
.length
;
70 const epSquare
= this.epSquares
[Lep
-1]; //always at least one element
71 if (!!epSquare
&& epSquare
.x
== x
+shiftX
&& epSquare
.y
== y
)
73 let enpassantMove
= this.getBasicMove([x
,y
], [x
+shiftX
,y
]);
74 enpassantMove
.vanish
.push({
78 c: this.getColor(epSquare
.x
,epSquare
.y
)
80 moves
.push(enpassantMove
);
86 isAttackedByPawn([x
,y
], colors
)
90 let pawnShift
= (c
=="w" ? 1 : -1);
91 if (x
+pawnShift
>=0 && x
+pawnShift
<V
.size
.x
)
93 if (this.getPiece(x
+pawnShift
,y
)==V
.PAWN
&& this.getColor(x
+pawnShift
,y
)==c
)
101 const VariantRules
= BerolinaRules
;