393e407b91888538f9c98c95293e523dbe80c1a3
1 import ChessRules
from "/base_rules.js";
3 export default class CwdaRules
extends ChessRules
{
7 select: ChessRules
.Options
.select
.concat([
13 { label: "Colorbound Clobberers", value: 'C' },
14 { label: "Nutty Knights", value: 'N' },
15 { label: "Remarkable Rookies", value: 'R' },
16 { label: "Fide", value: 'F' }
24 { label: "Colorbound Clobberers", value: 'C' },
25 { label: "Nutty Knights", value: 'N' },
26 { label: "Remarkable Rookies", value: 'R' },
27 { label: "Fide", value: 'F' }
31 input: ChessRules
.Options
.input
,
32 styles: ChessRules
.Options
.styles
36 static get PiecesMap() {
38 // Colorbound Clobberers
68 genRandInitBaseFen() {
69 let s
= FenUtil
.setupPieces(
70 ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
72 randomness: this.options
["randomness"],
73 between: [{p1: 'k', p2: 'r'}],
82 for (const c
of ['w', 'b']) {
83 const army
= "army" + (c
== 'w' ? "1" : "2");
84 if (this.options
[army
] != 'F') {
85 for (let obj
of [s
, pawnLines
]) {
86 obj
[c
] = obj
[c
].split("")
87 .map(p
=> V
.PiecesMap
[this.options
[army
]][p
]).join("");
92 fen: s
.b
.join("") + "/" +
93 pawnLines
['b'] + "/8/8/8/8/" + pawnLines
['w'].toUpperCase() +
94 "/" + s
.w
.join("").toUpperCase(),
100 return Object
.assign(
101 { "armies": this.options
["army1"] + this.options
["army2"] },
106 setOtherVariables(fenParsed
) {
107 super.setOtherVariables(fenParsed
);
108 this.army1
= fenParsed
.armies
.charAt(0);
109 this.army2
= fenParsed
.armies
.charAt(1);
114 p
= this.getPiece(x
, y
);
115 return (super.isKing(x
, y
, p
) || ['a', 'e', 'm'].includes(p
));
118 // Helper to describe pieces movements
166 pieces(color
, x
, y
) {
167 const res
= super.pieces(color
, x
, y
);
168 return Object
.assign(
174 {steps: V
.steps
.d
, range: 1}
180 {steps: V
.steps
.a
, range: 1},
181 {steps: V
.steps
.r
, range: 1}
187 {steps: V
.steps
.d
, range: 1},
188 {steps: V
.steps
.a
, range: 1},
189 {steps: V
.steps
.b
, range: 1}
196 {steps: V
.steps
.n
, range: 1}
199 'm': { moveas: 'k' },
200 'z': { moveas: 'p' },
213 'e': { moveas: 'k' },
214 'v': { moveas: 'p' },
227 'a': { moveas: 'k' },
237 getPotentialN_rookMoves(sq
) {
239 const rookSteps
= [ [0, -1], [0, 1], [c
== 'w' ? -1 : 1, 0] ];
240 const backward
= (c
== 'w' ? 1 : -1);
241 const kingSteps
= [ [backward
, -1], [backward
, 0], [backward
, 1] ];
243 this.getSlideNJumpMoves(sq
, rookSteps
).concat(
244 this.getSlideNJumpMoves(sq
, kingSteps
, 1))
248 getPotentialN_knightMoves(sq
) {
250 this.getSlideNJumpMoves(sq
, V
.steps
.$n
, 1).concat(
251 this.getSlideNJumpMoves(sq
, V
.steps
.f
, 1))
255 getPotentialN_bishopMoves(sq
) {
256 const backward
= (this.turn
== 'w' ? 1 : -1);
258 [0, -1], [0, 1], [backward
, -1], [backward
, 0], [backward
, 1]
260 const forward
= -backward
;
261 const knightSteps
= [
262 [2*forward
, -1], [2*forward
, 1], [forward
, -2], [forward
, 2]
265 this.getSlideNJumpMoves(sq
, knightSteps
, 1).concat(
266 this.getSlideNJumpMoves(sq
, kingSteps
, 1))
270 getPotentialN_queenMoves(sq
) {
271 const backward
= (this.turn
== 'w' ? 1 : -1);
272 const forward
= -backward
;
274 [forward
, -1], [forward
, 1],
275 [backward
, -1], [backward
, 0], [backward
, 1]
277 const knightSteps
= [
278 [2*forward
, -1], [2*forward
, 1], [forward
, -2], [forward
, 2]
280 const rookSteps
= [ [0, -1], [0, 1], [forward
, 0] ];
282 this.getSlideNJumpMoves(sq
, rookSteps
).concat(
283 this.getSlideNJumpMoves(sq
, kingSteps
, 1)).concat(
284 this.getSlideNJumpMoves(sq
, knightSteps
, 1))
288 getPotentialR_rookMoves(sq
) {
289 return this.getSlideNJumpMoves(sq
, V
.steps
.r
, 4);
292 getPotentialR_knightMoves(sq
) {
294 this.getSlideNJumpMoves(sq
, V
.steps
.d
, 1).concat(
295 this.getSlideNJumpMoves(sq
, V
.steps
.w
, 1))
299 getPotentialR_bishopMoves(sq
) {
301 this.getSlideNJumpMoves(sq
, V
.steps
.d
, 1).concat(
302 this.getSlideNJumpMoves(sq
, V
.steps
.f
, 1)).concat(
303 this.getSlideNJumpMoves(sq
, V
.steps
.$3, 1))
307 getPotentialR_queenMoves(sq
) {
309 this.getSlideNJumpMoves(sq
, V
.steps
.r
).concat(
310 this.getSlideNJumpMoves(sq
, V
.steps
.n
, 1))
315 // Can promote in anything from the two current armies
317 for (let army
of ["army1", "army2"]) {
318 if (army
== "army2" && this.army2
== this.army1
) break;
319 switch (this[army
]) {
321 Array
.prototype.push
.apply(promotions
,
322 [V
.C_ROOK
, V
.C_KNIGHT
, V
.C_BISHOP
, V
.C_QUEEN
]);
326 Array
.prototype.push
.apply(promotions
,
327 [V
.N_ROOK
, V
.N_KNIGHT
, V
.N_BISHOP
, V
.N_QUEEN
]);
331 Array
.prototype.push
.apply(promotions
,
332 [V
.R_ROOK
, V
.R_KNIGHT
, V
.R_BISHOP
, V
.R_QUEEN
]);
336 Array
.prototype.push
.apply(promotions
,
337 [V
.ROOK
, V
.KNIGHT
, V
.BISHOP
, V
.QUEEN
]);
342 return super.getPotentialPawnMoves(sq
, promotions
);
344 default: return super.getPotentialMovesFrom(sq
);
347 getCastleMoves([x
, y
]) {
348 const color
= this.getColor(x
, y
);
349 let finalSquares
= [ [2, 3], [V
.size
.y
- 2, V
.size
.y
- 3] ];
351 (color
== 'w' && this.army1
== 'C') ||
352 (color
== 'b' && this.army2
== 'C')
354 // Colorbound castle long in an unusual way:
355 finalSquares
[0] = [1, 2];
357 return super.getCastleMoves([x
, y
], finalSquares
);