Commit | Line | Data |
---|---|---|
f3e90e30 BA |
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 | return Object.assign( | |
30 | { | |
31 | 'a': { | |
32 | // Move like a king, no attacks | |
33 | "class": "antiking", | |
34 | moves: super.pieces(color, x, y)['k'].moves, | |
35 | attack: [] | |
36 | } | |
37 | }, | |
38 | super.pieces(color, x, y) | |
39 | ); | |
40 | } | |
41 | ||
42 | isKing(x, y, p) { | |
43 | if (!p) | |
44 | p = this.getPiece(x, y); | |
45 | return ['k', 'a'].includes(p); | |
46 | } | |
47 | ||
48 | // NOTE: canTake includes (wrong) captures of antiking, | |
49 | // to not go to low-level using findDestSquares() | |
50 | canTake([x1, y1], [x2, y2]) { | |
51 | const piece1 = this.getPiece(x1, y1); | |
52 | const color1 = this.getColor(x1, y1); | |
53 | const color2 = this.getColor(x2, y2); | |
54 | return ( | |
55 | (piece1 != 'a' && color1 != color2) || | |
56 | (piece1 == 'a' && color1 == color2) | |
57 | ); | |
58 | } | |
59 | ||
60 | // Remove captures of antiking (see above) | |
61 | getPotentialMovesFrom([x, y]) { | |
62 | return super.getPotentialMovesFrom([x, y]).filter(m => | |
63 | m.vanish.length == 1 || m.vanish[1].p != 'a'); | |
64 | } | |
65 | ||
66 | underCheck(squares, color) { | |
67 | let res = false; | |
68 | squares.forEach(sq => { | |
69 | switch (this.getPiece(sq[0], sq[1])) { | |
70 | case 'k': | |
71 | res ||= super.underAttack(sq, color); | |
72 | break; | |
73 | case 'a': | |
74 | res ||= !super.underAttack(sq, color); | |
75 | break; | |
76 | } | |
77 | }); | |
78 | return res; | |
79 | } | |
80 | ||
81 | }; |