Commit | Line | Data |
---|---|---|
33b42748 | 1 | import ChessRules from "/base_rules.js"; |
7c038235 | 2 | import {FenUtil} from "/utils/setupPieces.js"; |
33b42748 BA |
3 | |
4 | export default class BalaklavaRules extends ChessRules { | |
5 | ||
6 | get pawnPromotions() { | |
7 | return ['r', 'm', 'b', 'q']; | |
8 | } | |
9 | ||
10 | get hasEnpassant() { | |
11 | return false; | |
12 | } | |
13 | ||
14 | pieces(color, x, y) { | |
15 | let res = super.pieces(color, x, y); | |
16 | const knightSpec = res['n']; | |
17 | delete res['n']; | |
18 | res['m'] = { | |
19 | "class": "mammoth", | |
20 | both: [ | |
21 | { | |
22 | steps: [ | |
23 | [-2, -2], [-2, 0], [-2, 2], | |
24 | [0, -2], [0, 2], [2, -2], | |
25 | [2, 0], [2, 2] | |
26 | ], | |
27 | range: 1 | |
28 | } | |
29 | ] | |
30 | }; | |
0437a28b | 31 | ['p', 'r', 'b', 'm', 'q'].forEach(p => res[p].moves = knightSpec.moves); |
33b42748 BA |
32 | return res; |
33 | } | |
34 | ||
35 | genRandInitBaseFen() { | |
7c038235 | 36 | const s = FenUtil.setupPieces( |
10c9010b BA |
37 | ['r', 'm', 'b', 'q', 'k', 'b', 'm', 'r'], |
38 | { | |
39 | randomness: this.options["randomness"], | |
40 | diffCol: ['b'] | |
41 | } | |
42 | ); | |
33b42748 | 43 | return { |
7c038235 BA |
44 | fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + |
45 | s.w.join("").toUpperCase(), | |
46 | o: {} | |
33b42748 BA |
47 | }; |
48 | } | |
49 | ||
50 | pawnPostProcess(moves) { | |
51 | if (moves.length == 0) | |
52 | return []; | |
53 | const color = moves[0].vanish[0].c; | |
54 | const lastRank = (color == 'w' ? 0 : this.size.x - 1); | |
0437a28b | 55 | const forward = (color == 'w' ? -1 : 1); |
33b42748 BA |
56 | const noKnightPromotions = moves.filter(m => { |
57 | return ( | |
0437a28b | 58 | (m.end.x - m.start.x) * forward > 0 && |
33b42748 | 59 | ( |
0437a28b BA |
60 | m.end.x != lastRank || |
61 | ( | |
62 | Math.abs(m.start.x - m.end.x) <= 1 && | |
63 | Math.abs(m.start.y - m.end.y) <= 1 | |
64 | ) | |
33b42748 BA |
65 | ) |
66 | ); | |
67 | }); | |
68 | return super.pawnPostProcess(noKnightPromotions); | |
69 | } | |
70 | ||
71 | }; |