1 class CrazyhouseRules
extends ChessRules
5 super.initVariables(fen
);
6 // Also init reserves (used by the interface to show landing pieces)
7 const V
= VariantRules
;
27 // May be a continuation: adjust numbers of pieces according to captures + rebirths
28 this.moves
.forEach(m
=> {
29 if (m
.vanish
.length
== 2)
30 this.reserve
[m
.appear
[0].c
][m
.vanish
[1].p
]++;
31 else if (m
.vanish
.length
== 0)
32 this.reserve
[m
.appear
[0].c
][m
.appear
[0].p
]--;
36 // Used by the interface:
37 getReservePpath(color
, index
)
39 return color
+ VariantRules
.RESERVE_PIECES
[index
];
42 // Put an ordering on reserve pieces
43 static get RESERVE_PIECES() {
44 const V
= VariantRules
;
45 return [V
.PAWN
,V
.ROOK
,V
.KNIGHT
,V
.BISHOP
,V
.QUEEN
];
48 getReserveMoves([x
,y
])
50 const color
= this.turn
;
51 const p
= VariantRules
.RESERVE_PIECES
[y
];
52 if (this.reserve
[color
][p
] == 0)
55 for (let i
=0; i
<sizeX
; i
++)
57 for (let j
=0; j
<sizeY
; j
++)
59 if (this.board
[i
][j
] != VariantRules
.EMPTY
)
78 getPotentialMovesFrom([x
,y
])
80 const sizeX
= VariantRules
.size
[0];
82 return super.getPotentialMovesFrom([x
,y
]);
83 // Reserves, outside of board: x == sizeX
84 return this.getReserveMoves([x
,y
]);
89 let moves
= super.getAllValidMoves();
90 const color
= this.turn
;
91 const sizeX
= VariantRules
.size
[0];
92 for (let i
=0; i
<VariantRules
.RESERVE_PIECES
.length
; i
++)
93 moves
= moves
.concat(this.getReserveMoves([sizeX
,i
]));
94 return this.filterValid(moves
);
99 if (!super.atLeastOneMove())
101 const sizeX
= VariantRules
.size
[0];
102 // Scan for reserve moves
103 for (let i
=0; i
<VariantRules
.RESERVE_PIECES
.length
; i
++)
105 let moves
= this.filterValid(this.getReserveMoves([sizeX
,i
]));
106 if (moves
.length
> 0)
114 updateVariables(move)
116 super.updateVariables(move);
117 const color
= this.turn
;
118 if (move.vanish
.length
==2)
119 this.reserve
[color
][move.appear
[0].p
]++;
120 if (move.vanish
.length
==0)
121 this.reserve
[color
][move.appear
[0].p
]--;
124 unupdateVariables(move)
126 super.unupdateVariables(move);
127 const color
= this.turn
;
128 if (move.vanish
.length
==2)
129 this.reserve
[color
][move.appear
[0].p
]--;
130 if (move.vanish
.length
==0)
131 this.reserve
[color
][move.appear
[0].p
]++;
134 static get SEARCH_DEPTH() { return 2; } //high branching factor
138 if (move.vanish
.length
> 0)
139 return super.getNotation(move);
142 (move.appear
[0].p
!= VariantRules
.PAWN
? move.appear
.p
.toUpperCase() : "");
144 String
.fromCharCode(97 + move.end
.y
) + (VariantRules
.size
[0]-move.end
.x
);
145 return piece
+ "@" + finalSquare
;