Commit | Line | Data |
---|---|---|
33b42748 BA |
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 | }; | |
0437a28b | 30 | ['p', 'r', 'b', 'm', 'q'].forEach(p => res[p].moves = knightSpec.moves); |
33b42748 BA |
31 | return res; |
32 | } | |
33 | ||
34 | genRandInitBaseFen() { | |
35 | const baseFen = super.genRandInitBaseFen(); | |
36 | return { | |
9aebe2aa | 37 | fen: baseFen.fen.replace(/n/g, 'm').replace(/N/g, 'M'), |
33b42748 BA |
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); | |
0437a28b | 47 | const forward = (color == 'w' ? -1 : 1); |
33b42748 BA |
48 | const noKnightPromotions = moves.filter(m => { |
49 | return ( | |
0437a28b | 50 | (m.end.x - m.start.x) * forward > 0 && |
33b42748 | 51 | ( |
0437a28b BA |
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 | ) | |
33b42748 BA |
57 | ) |
58 | ); | |
59 | }); | |
60 | return super.pawnPostProcess(noKnightPromotions); | |
61 | } | |
62 | ||
63 | }; |