ac9aedc3ef777818370a9520d647072939795d45
[xogo.git] / variants / _Antiking / class.js
1 import ChessRules from "/base_rules.js";
2
3 export 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) {
29 let antikingSpec = super.pieces(color, x, y)['k'];
30 antikingSpec["class"] = "antiking";
31 return Object.assign({'a': antikingSpec}, super.pieces(color, x, y));
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
58 underCheck(square_s, color) {
59 let res = false;
60 square_s.forEach(sq => {
61 switch (this.getPiece(sq[0], sq[1])) {
62 case 'k':
63 res ||= super.underAttack(sq, color);
64 break;
65 case 'a':
66 res ||= !super.underAttack(sq, color);
67 break;
68 }
69 });
70 return res;
71 }
72
73 };