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