Fix Balaklava, draft Bario complete rules
[xogo.git] / variants / Balaklava / class.js
1 import ChessRules from "/base_rules.js";
2
3 export default class BalaklavaRules extends ChessRules {
4
5 get pawnPromotions() {
6 return ['r', 'm', 'b', 'q'];
7 }
8
9 get hasEnpassant() {
10 return false;
11 }
12
13 pieces(color, x, y) {
14 let res = super.pieces(color, x, y);
15 const knightSpec = res['n'];
16 delete res['n'];
17 res['m'] = {
18 "class": "mammoth",
19 both: [
20 {
21 steps: [
22 [-2, -2], [-2, 0], [-2, 2],
23 [0, -2], [0, 2], [2, -2],
24 [2, 0], [2, 2]
25 ],
26 range: 1
27 }
28 ]
29 };
30 ['p', 'r', 'b', 'm', 'q'].forEach(p => res[p].moves = knightSpec.moves);
31 return res;
32 }
33
34 genRandInitBaseFen() {
35 const baseFen = super.genRandInitBaseFen();
36 return {
37 fen: baseFen.fen.replace(/n/g, 'm').replace(/N/g, 'M'),
38 o: baseFen.o
39 };
40 }
41
42 pawnPostProcess(moves) {
43 if (moves.length == 0)
44 return [];
45 const color = moves[0].vanish[0].c;
46 const lastRank = (color == 'w' ? 0 : this.size.x - 1);
47 const forward = (color == 'w' ? -1 : 1);
48 const noKnightPromotions = moves.filter(m => {
49 return (
50 (m.end.x - m.start.x) * forward > 0 &&
51 (
52 m.end.x != lastRank ||
53 (
54 Math.abs(m.start.x - m.end.x) <= 1 &&
55 Math.abs(m.start.y - m.end.y) <= 1
56 )
57 )
58 );
59 });
60 return super.pawnPostProcess(noKnightPromotions);
61 }
62
63 };