Commit | Line | Data |
---|---|---|
6bf2ab34 | 1 | import ChessRules from "/base_rules.js"; |
ecd7d190 BA |
2 | |
3 | export default class ClorangeRules extends ChessRules { | |
4 | ||
5269839f BA |
5 | static get Options() { |
6 | return { | |
7 | select: C.Options.select, | |
8 | styles: | |
9 | C.Options.styles.filter(s => !["crazyhouse","recycle"].includes(s)) | |
10 | }; | |
11 | } | |
6bf2ab34 | 12 | |
ecd7d190 BA |
13 | get hasReserve() { |
14 | return true; | |
15 | } | |
16 | ||
6bf2ab34 BA |
17 | pieces(color, x, y) { |
18 | let res = super.pieces(color, x, y); | |
19 | res['s'] = {"class": "nv-pawn", moveas: "p"}; | |
20 | res['u'] = {"class": "nv-rook", moveas: "r"}; | |
21 | res['o'] = {"class": "nv-knight", moveas: "n"}; | |
22 | res['c'] = {"class": "nv-bishop", moveas: "b"}; | |
23 | res['t'] = {"class": "nv-queen", moveas: "q"}; | |
5269839f | 24 | return res; |
ecd7d190 BA |
25 | } |
26 | ||
5269839f BA |
27 | static get V_PIECES() { |
28 | return ['p', 'r', 'n', 'b', 'q']; | |
29 | } | |
30 | static get NV_PIECES() { | |
31 | return ['s', 'u', 'o', 'c', 't']; | |
ecd7d190 | 32 | } |
3232aba3 BA |
33 | static get ReserveArray() { |
34 | return V.V_PIECES.concat(V.NV_PIECES); | |
ecd7d190 BA |
35 | } |
36 | ||
5269839f | 37 | // Forbid non-violent pieces to capture |
ecd7d190 BA |
38 | canTake([x1, y1], [x2, y2]) { |
39 | return ( | |
40 | this.getColor(x1, y1) !== this.getColor(x2, y2) && | |
5269839f | 41 | (['k'].concat(V.V_PIECES)).includes(this.getPiece(x1, y1)) |
ecd7d190 BA |
42 | ); |
43 | } | |
44 | ||
c20e2566 BA |
45 | pawnPostProcess(moves, color, oppCols) { |
46 | let res = super.pawnPostProcess(moves, color, oppCols); | |
47 | if (res.length > 0 && res[0].vanish[0].p == 's') { | |
48 | // Fix promotions of non-violent pawns (if any) | |
49 | res.forEach(m => { | |
50 | if (m.appear[0].p != 's') | |
51 | m.appear[0].p = V.NV_PIECES[V.V_PIECES.indexOf(m.appear[0].p)]; | |
52 | }); | |
53 | } | |
54 | return res; | |
55 | } | |
56 | ||
ecd7d190 BA |
57 | prePlay(move) { |
58 | super.prePlay(move); | |
c20e2566 BA |
59 | // NOTE: drop moves already taken into account in base prePlay() |
60 | if (move.vanish.length == 2 && move.appear.length == 1) { | |
61 | const normal = V.V_PIECES.includes(move.vanish[1].p); | |
62 | const pIdx = | |
63 | (normal ? V.V_PIECES : V.NV_PIECES).indexOf(move.vanish[1].p); | |
5269839f | 64 | const resPiece = (normal ? V.NV_PIECES : V.V_PIECES)[pIdx]; |
c20e2566 BA |
65 | super.updateReserve(C.GetOppTurn(this.turn), resPiece, |
66 | this.reserve[C.GetOppTurn(this.turn)][resPiece] + 1); | |
ecd7d190 BA |
67 | } |
68 | } | |
69 | ||
70 | }; |