Some fixes. Loser implemented. Draft Extinction,Crazyhouse,Switching
[vchess.git] / public / javascripts / variants / Crazyhouse.js
CommitLineData
a6abf094
BA
1class CrazyhouseRules extends ChessRules
2{
3 initVariables(fen)
4 {
5 super.initVariables();
6 // Also init reserves (used by the interface to show landing pieces)
7 const V = VariantRules;
8 this.reserve =
9 {
10 "w":
11 {
12 [V.PAWN]: 0,
13 [V.ROOK]: 0,
14 [V.KNIGHT]: 0,
15 [V.BISHOP]: 0,
16 [V.QUEEN]: 0,
17 },
18 "b":
19 {
20 [V.PAWN]: 0,
21 [V.ROOK]: 0,
22 [V.KNIGHT]: 0,
23 [V.BISHOP]: 0,
24 [V.QUEEN]: 0,
25 }
26 };
27 // It may be a continuation: adjust numbers of pieces according to captures + rebirths
28 // TODO
29 }
30
31 // Used by the interface:
32 getReservePieces(color)
33 {
34 return {
35 [color+V.PAWN]: this.reserve[color][V.PAWN],
36 [color+V.ROOK]: this.reserve[color][V.ROOK],
37 [color+V.KNIGHT]: this.reserve[color][V.KNIGHT],
38 [color+V.BISHOP]: this.reserve[color][V.BISHOP],
39 [color+V.QUEEN]: this.reserve[color][V.QUEEN],
40 };
41 }
42
43 getPotentialMovesFrom([x,y])
44 {
45 let moves = super.getPotentialMovesFrom([x,y]);
46 // Add landing moves:
47 const color = this.turn;
48 Object.keys(this.reserve[color]).forEach(p => {
49
50 moves.push(...); //concat... just appear
51 });
52 return moves;
53 }
54
55 // TODO: condition "if this is reserve" --> special square !!! coordinates ??
56 getPossibleMovesFrom(sq)
57 {
58 // Assuming color is right (already checked)
59 return this.filterValid( this.getPotentialMovesFrom(sq) );
60 }
61
62 // TODO: add reserve moves
63 getAllValidMoves()
64 {
65
66 }
67
68 // TODO: also
69 atLeastOneMove()
70 {
71
72 }
73
74 // TODO: update reserve
75 updateVariables(move)
76 {
77 }
78 unupdateVariables(move)
79 {
80 }
81
82 static get SEARCH_DEPTH() { return 2; } //high branching factor
83
84 getNotation(move)
85 {
86 if (move.vanish.length > 0)
87 return super.getNotation(move);
88 // Rebirth:
89 const piece =
90 (move.appear[0].p != VariantRules.PAWN ? move.appear.p.toUpperCase() : "");
91 const finalSquare =
92 String.fromCharCode(97 + move.end.y) + (VariantRules.size[0]-move.end.x);
93 return piece + "@" + finalSquare;
94 }
95}