Draft Capablanca chess + add TODO related to move transmission issues
[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 'a': {
27 "class": "amazon",
33b42748 28 both: [
c9ab0340
BA
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 43 },
b99ce1fb
BA
44 'e': {
45 "class": "empress",
33b42748 46 both: [
57b8015b
BA
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 ]
b99ce1fb 60 },
57b8015b
BA
61 's': {
62 "class": "princess",
33b42748 63 both: [
57b8015b
BA
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 ]
c9ab0340
BA
77 }
78 };
57b8015b 79 return Object.assign(fusions, super.pieces(color, x, y));
b99ce1fb
BA
80 }
81
82 static get MergeComposed() {
83 return {
84 "be": "a",
57b8015b
BA
85 "bq": "q",
86 "br": "q",
b99ce1fb 87 "bs": "s",
57b8015b 88 "eq": "a",
b99ce1fb 89 "er": "e",
57b8015b 90 "es": "a",
b99ce1fb 91 "rs": "a",
57b8015b 92 "qr": "q",
b99ce1fb 93 "qs": "a",
57b8015b 94 "rs": "a"
b99ce1fb
BA
95 };
96 }
97
57b8015b 98 // Assumption p1 != p2
b99ce1fb 99 static Fusion(p1, p2) {
57b8015b
BA
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";
b99ce1fb 113 // p1 or p2 already have knight + other piece
57b8015b 114 return (p1 == "n" ? p2 : p1);
b99ce1fb 115 }
57b8015b
BA
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("")];
b99ce1fb
BA
120 }
121
57b8015b
BA
122 // TODO: interaction with rifle ?
123 postProcessPotentialMoves(moves) {
b99ce1fb
BA
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 ||
57b8015b
BA
129 m.vanish[0].p != "p" ||
130 ["p", "q"].includes(m.appear[0].p)
b99ce1fb
BA
131 );
132 });
133 moves.forEach(m => {
134 if (
135 m.vanish.length == 2 &&
136 m.appear.length == 1 &&
57b8015b 137 m.vanish[0].p != m.vanish[1].p
b99ce1fb
BA
138 ) {
139 // Augment pieces abilities in case of captures
57b8015b 140 m.appear[0].p = V.Fusion(m.vanish[0].p, m.vanish[1].p);
b99ce1fb
BA
141 }
142 });
635418a5 143 return super.postProcessPotentialMoves(moves);
b99ce1fb
BA
144 }
145
146};