Almost finished Clorange draft
[xogo.git] / variants / Clorange / class.js
1 import ChessRules from "/base_rules.js";
2
3 export default class ClorangeRules extends ChessRules {
4
5 // TODO: options : disable teleport/recycle at least ?
6
7 get hasReserve() {
8 return true;
9 }
10
11 getReserveFen(o) {
12 if (o.init)
13 return "00000000000000000000";
14 return (
15 ["w","b"].map(c => Object.values(this.reserve[c]).join("")).join("")
16 );
17 }
18
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"};
26 }
27
28 setOtherVariables(fen) {
29 super.setOtherVariables(fen,
30 ['p', 'r', 'n', 'b', 'q', 's', 'u', 'o', 'c', 't']);
31 }
32
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 });
42 }
43
44 canTake([x1, y1], [x2, y2]) {
45 return (
46 this.getColor(x1, y1) !== this.getColor(x2, y2) &&
47 ['p', 'r', 'n', 'b', 'q', 'k'].includes(this.getPiece(x1, y1))
48 );
49 }
50
51 prePlay(move) {
52 super.prePlay(move);
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
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 };