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