3e8d391ae673f64496ffeb2ca30e978542b39db8
[xogo.git] / variants / Absorption / class.js
1 import ChessRules from "/base_rules.js";
2
3 export default class AbsorptionRules extends ChessRules {
4
5 static get Options() {
6 return {
7 select: C.Options.select,
8 styles: [
9 "balance",
10 "capture",
11 "cylinder",
12 "dark",
13 "doublemove",
14 "progressive",
15 "recycle",
16 //"rifle", //TODO
17 "teleport",
18 "zen"
19 ]
20 };
21 }
22
23 pieces(color, x, y) {
24 let fusions = {
25 // amazon
26 'a': {
27 "class": "amazon",
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 }
42 ]
43 },
44 // empress
45 'e': {
46 "class": "empress",
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 ]
61 },
62 // princess
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 ]
79 }
80 };
81 return Object.assign(fusions, super.pieces(color, x, y));
82 }
83
84 static get MergeComposed() {
85 return {
86 "be": "a",
87 "bq": "q",
88 "br": "q",
89 "bs": "s",
90 "eq": "a",
91 "er": "e",
92 "es": "a",
93 "rs": "a",
94 "qr": "q",
95 "qs": "a",
96 "rs": "a"
97 };
98 }
99
100 // Assumption p1 != p2
101 static Fusion(p1, p2) {
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";
115 // p1 or p2 already have knight + other piece
116 return (p1 == "n" ? p2 : p1);
117 }
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("")];
122 }
123
124 // TODO: interaction with rifle ?
125 postProcessPotentialMoves(moves) {
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 ||
131 m.vanish[0].p != "p" ||
132 ["p", "q"].includes(m.appear[0].p)
133 );
134 });
135 moves.forEach(m => {
136 if (
137 m.vanish.length == 2 &&
138 m.appear.length == 1 &&
139 m.vanish[0].p != m.vanish[1].p
140 ) {
141 // Augment pieces abilities in case of captures
142 m.appear[0].p = V.Fusion(m.vanish[0].p, m.vanish[1].p);
143 }
144 });
145 return super.postProcessPotentialMoves(moves);
146 }
147
148 };