Commit | Line | Data |
---|---|---|
a548cb4e BA |
1 | import ChessRules from "/base_rules.js"; |
2 | ||
3 | export class AbstractAntikingRules extends ChessRules { | |
4 | ||
5 | static get Options() { | |
6 | return { | |
7 | styles: [ | |
8 | "atomic", | |
9 | "balance", | |
10 | "cannibal", | |
11 | "capture", | |
12 | "crazyhouse", | |
13 | "doublemove", | |
14 | "madrasi", | |
15 | "progressive", | |
16 | "recycle", | |
17 | "rifle", | |
18 | "teleport", | |
19 | "zen" | |
20 | ] | |
21 | }; | |
22 | } | |
23 | ||
24 | pieces(color, x, y) { | |
25 | "a": { | |
26 | // Move like a king, no attacks | |
27 | "class": "antiking", | |
28 | moves: super.pieces(color, x, y)['k'].moves, | |
29 | attack: [] | |
30 | } | |
31 | } | |
32 | ||
33 | isKing(x, y, p) { | |
34 | if (!p) | |
35 | p = this.getPiece(x, y); | |
36 | return ['k', 'a'].includes(p); | |
37 | } | |
38 | ||
39 | canTake([x1, y1], [x2, y2]) { | |
40 | const piece1 = this.getPiece(x1, y1); | |
41 | const piece2 = this.getPiece(x2, y2); | |
42 | const color1 = this.getColor(x1, y1); | |
43 | const color2 = this.getColor(x2, y2); | |
44 | return ( | |
45 | piece2 != 'a' && | |
46 | ( | |
47 | (piece1 != 'a' && color1 != color2) || | |
48 | (piece1 == 'a' && color1 == color2) | |
49 | ) | |
50 | ); | |
51 | } | |
52 | ||
53 | underCheck(squares, color) { | |
54 | const oppCol = C.GetOppCol(color); | |
55 | let res = false; | |
56 | squares.forEach(sq => { | |
57 | switch (this.getPiece(sq[0], sq[1])) { | |
58 | case 'k': | |
59 | res ||= super.underAttack(sq, oppCol); | |
60 | break; | |
61 | case 'a': | |
62 | res ||= !super.underAttack(sq, oppCol); | |
63 | break; | |
64 | } | |
65 | }); | |
66 | return res; | |
67 | } | |
68 | ||
69 | }; |