Draft Bario (unfinished)
[xogo.git] / variants / _Antiking / class.js
CommitLineData
f3e90e30
BA
1import ChessRules from "/base_rules.js";
2
3export default class AbstractAntikingRules extends ChessRules {
4
5 static get Aliases() {
6 return Object.assign({'A': AbstractAntikingRules}, ChessRules.Aliases);
7 }
8
9 static get Options() {
10 return {
11 styles: [
12 "atomic",
13 "balance",
14 "cannibal",
15 "capture",
16 "crazyhouse",
17 "doublemove",
18 "madrasi",
19 "progressive",
20 "recycle",
21 "rifle",
22 "teleport",
23 "zen"
24 ]
25 };
26 }
27
28 pieces(color, x, y) {
006c778a
BA
29 let antikingSpec = super.pieces(color, x, y)['k'];
30 antikingSpec["class"] = "antiking";
31 return Object.assign({'a': antikingSpec}, super.pieces(color, x, y));
f3e90e30
BA
32 }
33
34 isKing(x, y, p) {
35 if (!p)
36 p = this.getPiece(x, y);
37 return ['k', 'a'].includes(p);
38 }
39
40 // NOTE: canTake includes (wrong) captures of antiking,
41 // to not go to low-level using findDestSquares()
42 canTake([x1, y1], [x2, y2]) {
43 const piece1 = this.getPiece(x1, y1);
44 const color1 = this.getColor(x1, y1);
45 const color2 = this.getColor(x2, y2);
46 return (
47 (piece1 != 'a' && color1 != color2) ||
48 (piece1 == 'a' && color1 == color2)
49 );
50 }
51
52 // Remove captures of antiking (see above)
53 getPotentialMovesFrom([x, y]) {
54 return super.getPotentialMovesFrom([x, y]).filter(m =>
55 m.vanish.length == 1 || m.vanish[1].p != 'a');
56 }
57
f31de5e4 58 underCheck(square_s, color) {
f3e90e30 59 let res = false;
f31de5e4
BA
60 if (!Array.isArray(square_s[0]))
61 square_s = [square_s];
62 square_s.forEach(sq => {
f3e90e30
BA
63 switch (this.getPiece(sq[0], sq[1])) {
64 case 'k':
65 res ||= super.underAttack(sq, color);
66 break;
67 case 'a':
68 res ||= !super.underAttack(sq, color);
69 break;
70 }
71 });
72 return res;
73 }
74
75};