Commit | Line | Data |
---|---|---|
6bf2ab34 | 1 | import ChessRules from "/base_rules.js"; |
ecd7d190 BA |
2 | |
3 | export default class ClorangeRules extends ChessRules { | |
4 | ||
6bf2ab34 BA |
5 | // TODO: options : disable teleport/recycle at least ? |
6 | ||
ecd7d190 BA |
7 | get hasReserve() { |
8 | return true; | |
9 | } | |
10 | ||
6bf2ab34 BA |
11 | getReserveFen(o) { |
12 | if (o.init) | |
13 | return "00000000000000000000"; | |
ecd7d190 | 14 | return ( |
6bf2ab34 | 15 | ["w","b"].map(c => Object.values(this.reserve[c]).join("")).join("") |
ecd7d190 BA |
16 | ); |
17 | } | |
18 | ||
6bf2ab34 BA |
19 | pieces(color, x, y) { |
20 | let res = super.pieces(color, x, y); | |
21 | res['s'] = {"class": "nv-pawn", moveas: "p"}; | |
22 | res['u'] = {"class": "nv-rook", moveas: "r"}; | |
23 | res['o'] = {"class": "nv-knight", moveas: "n"}; | |
24 | res['c'] = {"class": "nv-bishop", moveas: "b"}; | |
25 | res['t'] = {"class": "nv-queen", moveas: "q"}; | |
ecd7d190 BA |
26 | } |
27 | ||
28 | setOtherVariables(fen) { | |
6bf2ab34 BA |
29 | super.setOtherVariables(fen, |
30 | ['p', 'r', 'n', 'b', 'q', 's', 'u', 'o', 'c', 't']); | |
ecd7d190 BA |
31 | } |
32 | ||
6bf2ab34 BA |
33 | postProcessPotentialMoves(moves) { |
34 | // Remove captures for non-violent pieces: | |
35 | return super.postProcessPotentialMoves(moves).filter(m => { | |
36 | return ( | |
37 | m.vanish.length != 2 || | |
38 | m.appear.length != 1 || | |
39 | ['p', 'r', 'n', 'b', 'q'].includes(m.vanish[0].p) | |
40 | ); | |
41 | }); | |
ecd7d190 BA |
42 | } |
43 | ||
44 | canTake([x1, y1], [x2, y2]) { | |
45 | return ( | |
46 | this.getColor(x1, y1) !== this.getColor(x2, y2) && | |
6bf2ab34 | 47 | ['p', 'r', 'n', 'b', 'q', 'k'].includes(this.getPiece(x1, y1)) |
ecd7d190 BA |
48 | ); |
49 | } | |
50 | ||
ecd7d190 BA |
51 | prePlay(move) { |
52 | super.prePlay(move); | |
6bf2ab34 BA |
53 | // No crazyhouse or recycle, so the last call didn't update reserve: |
54 | if (move.vanish.length == 2 && move.appear.length == 1) { | |
55 | // Capture: update reserves | |
56 | this.Reserve[move.vanish | |
57 | const pIdx = ['p', 'r', 'n', 'b', 'q'].indexOf(move.vanish[1].p); | |
58 | // TODO | |
59 | if normal | |
ecd7d190 BA |
60 | ? ChessRules.PIECES.findIndex(p => p == move.vanish[1].p) |
61 | : V.NON_VIOLENT.findIndex(p => p == move.vanish[1].p); | |
62 | const rPiece = (normal ? V.NON_VIOLENT : ChessRules.PIECES)[pIdx]; | |
63 | this.reserve[move.vanish[1].c][rPiece]++; | |
64 | } | |
65 | } | |
66 | ||
67 | }; |