New variant idea
[xogo.git] / variants / Absorption / class.js
... / ...
CommitLineData
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,
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 'a': {
27 "class": "amazon",
28 both: [
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 'e': {
45 "class": "empress",
46 both: [
47 {
48 steps: [
49 [1, 0], [-1, 0], [0, 1], [0, -1]
50 ]
51 },
52 {
53 steps: [
54 [1, 2], [1, -2], [-1, 2], [-1, -2],
55 [2, 1], [-2, 1], [2, -1], [-2, -1]
56 ],
57 range: 1
58 }
59 ]
60 },
61 's': {
62 "class": "princess",
63 both: [
64 {
65 steps: [
66 [1, 1], [1, -1], [-1, 1], [-1, -1]
67 ]
68 },
69 {
70 steps: [
71 [1, 2], [1, -2], [-1, 2], [-1, -2],
72 [2, 1], [-2, 1], [2, -1], [-2, -1]
73 ],
74 range: 1
75 }
76 ]
77 }
78 };
79 return Object.assign(fusions, super.pieces(color, x, y));
80 }
81
82 static get MergeComposed() {
83 return {
84 "be": "a",
85 "bq": "q",
86 "br": "q",
87 "bs": "s",
88 "eq": "a",
89 "er": "e",
90 "es": "a",
91 "rs": "a",
92 "qr": "q",
93 "qs": "a",
94 "rs": "a"
95 };
96 }
97
98 // Assumption p1 != p2
99 static Fusion(p1, p2) {
100 if (p1 == "k")
101 return p1;
102 if (p1 == "p")
103 return p2;
104 if (p2 == "p")
105 return p1;
106 if ([p1, p2].includes("n")) {
107 if ([p1, p2].includes("q"))
108 return "a";
109 if ([p1, p2].includes("r"))
110 return "e";
111 if ([p1, p2].includes("b"))
112 return "s";
113 // p1 or p2 already have knight + other piece
114 return (p1 == "n" ? p2 : p1);
115 }
116 if ([p1, p2].includes("a"))
117 return "a";
118 // No king, no pawn, no knight or amazon => 5 remaining pieces
119 return V.MergeComposed[[p1, p2].sort().join("")];
120 }
121
122 // TODO: interaction with rifle ?
123 postProcessPotentialMoves(moves) {
124 // Filter out capturing promotions (except one),
125 // because they are all the same.
126 moves = moves.filter(m => {
127 return (
128 m.vanish.length == 1 ||
129 m.vanish[0].p != "p" ||
130 ["p", "q"].includes(m.appear[0].p)
131 );
132 });
133 moves.forEach(m => {
134 if (
135 m.vanish.length == 2 &&
136 m.appear.length == 1 &&
137 m.vanish[0].p != m.vanish[1].p
138 ) {
139 // Augment pieces abilities in case of captures
140 m.appear[0].p = V.Fusion(m.vanish[0].p, m.vanish[1].p);
141 }
142 });
143 return super.postProcessPotentialMoves(moves);
144 }
145
146};