Untested draft refactor both/moves/attack for pieces specs
[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 ['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.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 noKnightPromotions = moves.filter(m => {
48 return (
49 m.end.x != lastRank ||
50 (
51 Math.abs(m.start.x - m.end.x) <= 1 &&
52 Math.abs(m.start.y - m.end.y) <= 1
53 )
54 );
55 });
56 return super.pawnPostProcess(noKnightPromotions);
57 }
58
59 };