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 | getReserveFen(o) { |
18 | if (o.init) | |
19 | return "00000000000000000000"; | |
ecd7d190 | 20 | return ( |
6bf2ab34 | 21 | ["w","b"].map(c => Object.values(this.reserve[c]).join("")).join("") |
ecd7d190 BA |
22 | ); |
23 | } | |
24 | ||
6bf2ab34 BA |
25 | pieces(color, x, y) { |
26 | let res = super.pieces(color, x, y); | |
27 | res['s'] = {"class": "nv-pawn", moveas: "p"}; | |
28 | res['u'] = {"class": "nv-rook", moveas: "r"}; | |
29 | res['o'] = {"class": "nv-knight", moveas: "n"}; | |
30 | res['c'] = {"class": "nv-bishop", moveas: "b"}; | |
31 | res['t'] = {"class": "nv-queen", moveas: "q"}; | |
5269839f | 32 | return res; |
ecd7d190 BA |
33 | } |
34 | ||
5269839f BA |
35 | static get V_PIECES() { |
36 | return ['p', 'r', 'n', 'b', 'q']; | |
37 | } | |
38 | static get NV_PIECES() { | |
39 | return ['s', 'u', 'o', 'c', 't']; | |
ecd7d190 BA |
40 | } |
41 | ||
5269839f BA |
42 | setOtherVariables(fen) { |
43 | super.setOtherVariables(fen, V.V_PIECES.concat(V.NV_PIECES)); | |
ecd7d190 BA |
44 | } |
45 | ||
5269839f | 46 | // Forbid non-violent pieces to capture |
ecd7d190 BA |
47 | canTake([x1, y1], [x2, y2]) { |
48 | return ( | |
49 | this.getColor(x1, y1) !== this.getColor(x2, y2) && | |
5269839f | 50 | (['k'].concat(V.V_PIECES)).includes(this.getPiece(x1, y1)) |
ecd7d190 BA |
51 | ); |
52 | } | |
53 | ||
ecd7d190 BA |
54 | prePlay(move) { |
55 | super.prePlay(move); | |
6bf2ab34 | 56 | // No crazyhouse or recycle, so the last call didn't update reserve: |
5269839f BA |
57 | if ( |
58 | (move.vanish.length == 2 && move.appear.length == 1) || | |
59 | move.vanish.length == 0 //drop | |
60 | ) { | |
61 | const trPiece = | |
62 | (move.vanish.length > 0 ? move.vanish[1].p : move.appear[0].p); | |
63 | const normal = V.V_PIECES.includes(trPiece); | |
64 | const pIdx = (normal ? V.V_PIECES : V.NV_PIECES).indexOf(trPiece); | |
65 | const resPiece = (normal ? V.NV_PIECES : V.V_PIECES)[pIdx]; | |
66 | if (move.vanish.length > 0) { | |
67 | super.updateReserve(C.GetOppTurn(this.turn), resPiece, | |
68 | this.reserve[C.GetOppTurn(this.turn)][resPiece] + 1); | |
69 | } | |
70 | else { | |
71 | super.updateReserve(this.turn, resPiece, | |
72 | this.reserve[this.turn][resPiece] - 1); | |
73 | } | |
ecd7d190 BA |
74 | } |
75 | } | |
76 | ||
77 | }; |