Add Hex: almost fine, still some issues with SVG + rescaling
[xogo.git] / variants / Absorption / class.js
CommitLineData
b99ce1fb
BA
1import ChessRules from "/base_rules.js";
2
3export default class AbsorptionRules extends ChessRules {
4
5 static get Options() {
6 return {
7 select: C.Options.select,
b99ce1fb
BA
8 styles: [
9 "balance",
10 "capture",
11 "cylinder",
12 "dark",
13 "doublemove",
14 "progressive",
15 "recycle",
57b8015b 16 //"rifle", //TODO
b99ce1fb
BA
17 "teleport",
18 "zen"
19 ]
20 };
21 }
22
57b8015b 23 pieces(color, x, y) {
c9ab0340 24 let fusions = {
b99ce1fb
BA
25 // amazon
26 'a': {
27 "class": "amazon",
c9ab0340
BA
28 moves: [
29 {
30 steps: [
31 [0, 1], [0, -1], [1, 0], [-1, 0],
32 [1, 1], [1, -1], [-1, 1], [-1, -1]
33 ]
34 },
35 {
36 steps: [
37 [1, 2], [1, -2], [-1, 2], [-1, -2],
38 [2, 1], [-2, 1], [2, -1], [-2, -1]
39 ],
40 range: 1
41 }
b99ce1fb 42 ]
b99ce1fb
BA
43 },
44 // empress
45 'e': {
46 "class": "empress",
57b8015b
BA
47 moves: [
48 {
49 steps: [
50 [1, 0], [-1, 0], [0, 1], [0, -1]
51 ]
52 },
53 {
54 steps: [
55 [1, 2], [1, -2], [-1, 2], [-1, -2],
56 [2, 1], [-2, 1], [2, -1], [-2, -1]
57 ],
58 range: 1
59 }
60 ]
b99ce1fb
BA
61 },
62 // princess
57b8015b
BA
63 's': {
64 "class": "princess",
65 moves: [
66 {
67 steps: [
68 [1, 1], [1, -1], [-1, 1], [-1, -1]
69 ]
70 },
71 {
72 steps: [
73 [1, 2], [1, -2], [-1, 2], [-1, -2],
74 [2, 1], [-2, 1], [2, -1], [-2, -1]
75 ],
76 range: 1
77 }
78 ]
c9ab0340
BA
79 }
80 };
57b8015b 81 return Object.assign(fusions, super.pieces(color, x, y));
b99ce1fb
BA
82 }
83
84 static get MergeComposed() {
85 return {
86 "be": "a",
57b8015b
BA
87 "bq": "q",
88 "br": "q",
b99ce1fb 89 "bs": "s",
57b8015b 90 "eq": "a",
b99ce1fb 91 "er": "e",
57b8015b 92 "es": "a",
b99ce1fb 93 "rs": "a",
57b8015b 94 "qr": "q",
b99ce1fb 95 "qs": "a",
57b8015b 96 "rs": "a"
b99ce1fb
BA
97 };
98 }
99
57b8015b 100 // Assumption p1 != p2
b99ce1fb 101 static Fusion(p1, p2) {
57b8015b
BA
102 if (p1 == "k")
103 return p1;
104 if (p1 == "p")
105 return p2;
106 if (p2 == "p")
107 return p1;
108 if ([p1, p2].includes("n")) {
109 if ([p1, p2].includes("q"))
110 return "a";
111 if ([p1, p2].includes("r"))
112 return "e";
113 if ([p1, p2].includes("b"))
114 return "s";
b99ce1fb 115 // p1 or p2 already have knight + other piece
57b8015b 116 return (p1 == "n" ? p2 : p1);
b99ce1fb 117 }
57b8015b
BA
118 if ([p1, p2].includes("a"))
119 return "a";
120 // No king, no pawn, no knight or amazon => 5 remaining pieces
121 return V.MergeComposed[[p1, p2].sort().join("")];
b99ce1fb
BA
122 }
123
57b8015b
BA
124 // TODO: interaction with rifle ?
125 postProcessPotentialMoves(moves) {
b99ce1fb
BA
126 // Filter out capturing promotions (except one),
127 // because they are all the same.
128 moves = moves.filter(m => {
129 return (
130 m.vanish.length == 1 ||
57b8015b
BA
131 m.vanish[0].p != "p" ||
132 ["p", "q"].includes(m.appear[0].p)
b99ce1fb
BA
133 );
134 });
135 moves.forEach(m => {
136 if (
137 m.vanish.length == 2 &&
138 m.appear.length == 1 &&
57b8015b 139 m.vanish[0].p != m.vanish[1].p
b99ce1fb
BA
140 ) {
141 // Augment pieces abilities in case of captures
57b8015b 142 m.appear[0].p = V.Fusion(m.vanish[0].p, m.vanish[1].p);
b99ce1fb
BA
143 }
144 });
635418a5 145 return super.postProcessPotentialMoves(moves);
b99ce1fb
BA
146 }
147
148};