Draft Circular chess. Move animation not per segments for now
[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 (anti)king,
41 // to detect attacks on (anti)kings.
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 (anti)king (see above)
53 getPotentialMovesFrom([x, y]) {
54 return super.getPotentialMovesFrom([x, y]).filter(m =>
55 m.vanish.length == 1 || !['k', 'a'].includes(m.vanish[1].p));
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 };