1 import { ChessRules
} from "@/base_rules";
3 export 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' }
34 static AbbreviateOptions(opts
) {
35 return opts
["army1"] + opts
["army2"];
38 static IsValidOptions(opts
) {
39 // Both armies filled, avoid Fide vs Fide
41 opts
.army1
&& opts
.army2
&&
42 (opts
.army1
!= 'F' || opts
.army2
!= 'F')
47 return (ChessRules
.PIECES
.includes(b
[1]) ? "" : "Cwda/") + b
;
50 static get PiecesMap() {
52 // Colorbound Clobberers
79 static GenRandInitFen(options
) {
80 const baseFen
= ChessRules
.GenRandInitFen(options
.randomness
);
81 let blackLine
= baseFen
.substr(0, 8);
82 if (options
.army2
!= 'F') {
83 blackLine
= blackLine
.split('')
84 .map(p
=> V
.PiecesMap
[options
.army2
][p
]).join('');
86 let whiteLine
= baseFen
.substr(35, 8);
87 if (options
.army1
!= 'F') {
88 whiteLine
= whiteLine
.split('')
89 .map(p
=> V
.PiecesMap
[options
.army1
][p
.toLowerCase()])
90 .join('').toUpperCase();
93 blackLine
+ baseFen
.substring(8, 35) + whiteLine
+
94 baseFen
.substr(43) + " " + options
.army1
+ options
.army2
98 setOtherVariables(fen
) {
99 super.setOtherVariables(fen
);
100 const armies
= V
.ParseFen(fen
).armies
;
101 this.army1
= armies
.charAt(0);
102 this.army2
= armies
.charAt(1);
105 static ParseFen(fen
) {
106 return Object
.assign(
107 { armies: fen
.split(" ")[5] },
108 ChessRules
.ParseFen(fen
)
112 static IsGoodFen(fen
) {
113 if (!ChessRules
.IsGoodFen(fen
)) return false;
114 const armies
= V
.ParseFen(fen
).armies
;
115 if (!armies
|| !armies
.match(/^[CNRF]{2,2}$/)) return false;
120 return super.getFen() + " " + this.army1
+ this.army2
;
123 static get C_ROOK() {
126 static get C_KNIGHT() {
129 static get C_BISHOP() {
132 static get C_QUEEN() {
135 static get N_ROOK() {
138 static get N_KNIGHT() {
141 static get N_BISHOP() {
144 static get N_QUEEN() {
147 static get R_ROOK() {
150 static get R_KNIGHT() {
153 static get R_BISHOP() {
156 static get R_QUEEN() {
160 static get PIECES() {
161 return ChessRules
.PIECES
.concat(
162 [V
.C_ROOK
, V
.C_KNIGHT
, V
.C_BISHOP
, V
.C_QUEEN
]).concat(
163 [V
.N_ROOK
, V
.N_KNIGHT
, V
.N_BISHOP
, V
.N_QUEEN
]).concat(
164 [V
.R_ROOK
, V
.R_KNIGHT
, V
.R_BISHOP
, V
.R_QUEEN
]);
167 getPotentialMovesFrom(sq
) {
168 switch (this.getPiece(sq
[0], sq
[1])) {
169 case V
.C_ROOK: return this.getPotentialC_rookMoves(sq
);
170 case V
.C_KNIGHT: return this.getPotentialC_knightMoves(sq
);
171 case V
.C_BISHOP: return this.getPotentialC_bishopMoves(sq
);
172 case V
.C_QUEEN: return this.getPotentialC_queenMoves(sq
);
173 case V
.N_ROOK: return this.getPotentialN_rookMoves(sq
);
174 case V
.N_KNIGHT: return this.getPotentialN_knightMoves(sq
);
175 case V
.N_BISHOP: return this.getPotentialN_bishopMoves(sq
);
176 case V
.N_QUEEN: return this.getPotentialN_queenMoves(sq
);
177 case V
.R_ROOK: return this.getPotentialR_rookMoves(sq
);
178 case V
.R_KNIGHT: return this.getPotentialR_knightMoves(sq
);
179 case V
.R_BISHOP: return this.getPotentialR_bishopMoves(sq
);
180 case V
.R_QUEEN: return this.getPotentialR_queenMoves(sq
);
182 // Can promote in anything from the two current armies
184 for (let army
of ["army1", "army2"]) {
185 if (army
== "army2" && this.army2
== this.army1
) break;
186 switch (this[army
]) {
188 Array
.prototype.push
.apply(promotions
,
189 [V
.C_ROOK
, V
.C_KNIGHT
, V
.C_BISHOP
, V
.C_QUEEN
]);
193 Array
.prototype.push
.apply(promotions
,
194 [V
.N_ROOK
, V
.N_KNIGHT
, V
.N_BISHOP
, V
.N_QUEEN
]);
198 Array
.prototype.push
.apply(promotions
,
199 [V
.R_ROOK
, V
.R_KNIGHT
, V
.R_BISHOP
, V
.R_QUEEN
]);
203 Array
.prototype.push
.apply(promotions
,
204 [V
.ROOK
, V
.KNIGHT
, V
.BISHOP
, V
.QUEEN
]);
209 return super.getPotentialPawnMoves(sq
, promotions
);
211 default: return super.getPotentialMovesFrom(sq
);
217 return Object
.assign(
266 getPotentialC_rookMoves(sq
) {
268 this.getSlideNJumpMoves(sq
, V
.steps
.b
).concat(
269 this.getSlideNJumpMoves(sq
, V
.steps
.d
, 1))
273 getPotentialC_knightMoves(sq
) {
275 this.getSlideNJumpMoves(sq
, V
.steps
.a
, 1).concat(
276 this.getSlideNJumpMoves(sq
, V
.steps
.r
, 1))
280 getPotentialC_bishopMoves(sq
) {
282 this.getSlideNJumpMoves(sq
, V
.steps
.d
, 1).concat(
283 this.getSlideNJumpMoves(sq
, V
.steps
.a
, 1)).concat(
284 this.getSlideNJumpMoves(sq
, V
.steps
.b
, 1))
288 getPotentialC_queenMoves(sq
) {
290 this.getSlideNJumpMoves(sq
, V
.steps
.b
).concat(
291 this.getSlideNJumpMoves(sq
, V
.steps
.n
, 1))
295 getPotentialN_rookMoves(sq
) {
297 const rookSteps
= [ [0, -1], [0, 1], [c
== 'w' ? -1 : 1, 0] ];
298 const backward
= (c
== 'w' ? 1 : -1);
299 const kingSteps
= [ [backward
, -1], [backward
, 0], [backward
, 1] ];
301 this.getSlideNJumpMoves(sq
, rookSteps
).concat(
302 this.getSlideNJumpMoves(sq
, kingSteps
, 1))
306 getPotentialN_knightMoves(sq
) {
307 const backward
= (this.turn
== 'w' ? 1 : -1);
309 [0, -1], [0, 1], [backward
, -1], [backward
, 0], [backward
, 1]
312 this.getSlideNJumpMoves(sq
, V
.steps
.$n
, 1).concat(
313 this.getSlideNJumpMoves(sq
, kingSteps
, 1))
317 getPotentialN_bishopMoves(sq
) {
318 const backward
= (this.turn
== 'w' ? 1 : -1);
320 [0, -1], [0, 1], [backward
, -1], [backward
, 0], [backward
, 1]
322 const forward
= -backward
;
323 const knightSteps
= [
324 [2*forward
, -1], [2*forward
, 1], [forward
, -2], [forward
, 2]
327 this.getSlideNJumpMoves(sq
, knightSteps
, 1).concat(
328 this.getSlideNJumpMoves(sq
, kingSteps
, 1))
332 getPotentialN_queenMoves(sq
) {
333 const backward
= (this.turn
== 'w' ? 1 : -1);
334 const forward
= -backward
;
336 [forward
, -1], [forward
, 1],
337 [backward
, -1], [backward
, 0], [backward
, 1]
339 const knightSteps
= [
340 [2*forward
, -1], [2*forward
, 1], [forward
, -2], [forward
, 2]
342 const rookSteps
= [ [0, -1], [0, 1], [forward
, 0] ];
344 this.getSlideNJumpMoves(sq
, rookSteps
).concat(
345 this.getSlideNJumpMoves(sq
, kingSteps
, 1)).concat(
346 this.getSlideNJumpMoves(sq
, knightSteps
, 1))
350 getPotentialR_rookMoves(sq
) {
351 return this.getSlideNJumpMoves(sq
, V
.steps
.r
, 4);
354 getPotentialR_knightMoves(sq
) {
356 this.getSlideNJumpMoves(sq
, V
.steps
.d
, 1).concat(
357 this.getSlideNJumpMoves(sq
, V
.steps
.w
, 1))
361 getPotentialR_bishopMoves(sq
) {
363 this.getSlideNJumpMoves(sq
, V
.steps
.d
, 1).concat(
364 this.getSlideNJumpMoves(sq
, V
.steps
.f
, 1)).concat(
365 this.getSlideNJumpMoves(sq
, V
.steps
.$3, 1))
369 getPotentialR_queenMoves(sq
) {
371 this.getSlideNJumpMoves(sq
, V
.steps
.r
).concat(
372 this.getSlideNJumpMoves(sq
, V
.steps
.n
, 1))
376 getCastleMoves([x
, y
]) {
377 const color
= this.getColor(x
, y
);
378 let finalSquares
= [ [2, 3], [V
.size
.y
- 2, V
.size
.y
- 3] ];
380 (color
== 'w' && this.army1
== 'C') ||
381 (color
== 'b' && this.army2
== 'C')
383 // Colorbound castle long in an unusual way:
384 finalSquares
[0] = [1, 2];
386 return super.getCastleMoves([x
, y
], finalSquares
);
389 isAttacked(sq
, color
) {
390 if (super.isAttackedByPawn(sq
, color
) || super.isAttackedByKing(sq
, color
))
392 for (let army
of ['C', 'N', 'R', 'F']) {
394 [this.army1
, this.army2
].includes(army
) &&
396 this["isAttackedBy" + army
+ "_rook"](sq
, color
) ||
397 this["isAttackedBy" + army
+ "_knight"](sq
, color
) ||
398 this["isAttackedBy" + army
+ "_bishop"](sq
, color
) ||
399 this["isAttackedBy" + army
+ "_queen"](sq
, color
)
408 isAttackedByC_rook(sq
, color
) {
410 this.isAttackedBySlideNJump(sq
, color
, V
.C_ROOK
, V
.steps
.b
) ||
411 this.isAttackedBySlideNJump(sq
, color
, V
.C_ROOK
, V
.steps
.d
, 1)
415 isAttackedByC_knight(sq
, color
) {
417 this.isAttackedBySlideNJump(sq
, color
, V
.C_KNIGHT
, V
.steps
.r
, 1) ||
418 this.isAttackedBySlideNJump(sq
, color
, V
.C_KNIGHT
, V
.steps
.a
, 1)
422 isAttackedByC_bishop(sq
, color
) {
424 this.isAttackedBySlideNJump(sq
, color
, V
.C_BISHOP
, V
.steps
.d
, 1) ||
425 this.isAttackedBySlideNJump(sq
, color
, V
.C_BISHOP
, V
.steps
.a
, 1) ||
426 this.isAttackedBySlideNJump(sq
, color
, V
.C_BISHOP
, V
.steps
.f
, 1)
430 isAttackedByC_queen(sq
, color
) {
432 this.isAttackedBySlideNJump(sq
, color
, V
.C_QUEEN
, V
.steps
.b
) ||
433 this.isAttackedBySlideNJump(sq
, color
, V
.C_QUEEN
, V
.steps
.n
, 1)
437 isAttackedByN_rook(sq
, color
) {
438 const rookSteps
= [ [0, -1], [0, 1], [color
== 'w' ? 1 : -1, 0] ];
439 const backward
= (color
== 'w' ? -1 : 1);
440 const kingSteps
= [ [backward
, -1], [backward
, 0], [backward
, 1] ];
442 this.isAttackedBySlideNJump(sq
, color
, V
.N_ROOK
, rookSteps
) ||
443 this.isAttackedBySlideNJump(sq
, color
, V
.N_ROOK
, kingSteps
, 1)
447 isAttackedByN_knight(sq
, color
) {
448 const backward
= (color
== 'w' ? -1 : 1);
450 [0, -1], [0, 1], [backward
, -1], [backward
, 0], [backward
, 1]
453 this.isAttackedBySlideNJump(sq
, color
, V
.N_KNIGHT
, V
.steps
.$n
) ||
454 this.isAttackedBySlideNJump(sq
, color
, V
.N_KNIGHT
, kingSteps
, 1)
458 isAttackedByN_bishop(sq
, color
) {
459 const backward
= (color
== 'w' ? -1 : 1);
461 [0, -1], [0, 1], [backward
, -1], [backward
, 0], [backward
, 1]
463 const forward
= -backward
;
464 const knightSteps
= [
465 [2*forward
, -1], [2*forward
, 1], [forward
, -2], [forward
, 2]
468 this.isAttackedBySlideNJump(sq
, color
, V
.N_BISHOP
, knightSteps
, 1) ||
469 this.isAttackedBySlideNJump(sq
, color
, V
.N_BISHOP
, kingSteps
, 1)
473 isAttackedByN_queen(sq
, color
) {
474 const backward
= (color
== 'w' ? -1 : 1);
475 const forward
= -backward
;
477 [forward
, -1], [forward
, 1],
478 [backward
, -1], [backward
, 0], [backward
, 1]
480 const knightSteps
= [
481 [2*forward
, -1], [2*forward
, 1], [forward
, -2], [forward
, 2]
483 const rookSteps
= [ [0, -1], [0, 1], [forward
, 0] ];
485 this.isAttackedBySlideNJump(sq
, color
, V
.N_QUEEN
, knightSteps
, 1) ||
486 this.isAttackedBySlideNJump(sq
, color
, V
.N_QUEEN
, kingSteps
, 1) ||
487 this.isAttackedBySlideNJump(sq
, color
, V
.N_QUEEN
, rookSteps
)
491 isAttackedByR_rook(sq
, color
) {
492 return this.isAttackedBySlideNJump(sq
, color
, V
.R_ROOK
, V
.steps
.r
, 4);
495 isAttackedByR_knight(sq
, color
) {
497 this.isAttackedBySlideNJump(sq
, color
, V
.R_KNIGHT
, V
.steps
.d
, 1) ||
498 this.isAttackedBySlideNJump(sq
, color
, V
.R_KNIGHT
, V
.steps
.w
, 1)
502 isAttackedByR_bishop(sq
, color
) {
504 this.isAttackedBySlideNJump(sq
, color
, V
.R_BISHOP
, V
.steps
.d
, 1) ||
505 this.isAttackedBySlideNJump(sq
, color
, V
.R_BISHOP
, V
.steps
.f
, 1) ||
506 this.isAttackedBySlideNJump(sq
, color
, V
.R_BISHOP
, V
.steps
.$3, 1)
510 isAttackedByR_queen(sq
, color
) {
512 this.isAttackedBySlideNJump(sq
, color
, V
.R_QUEEN
, V
.steps
.r
) ||
513 this.isAttackedBySlideNJump(sq
, color
, V
.R_QUEEN
, V
.steps
.n
, 1)
517 static get VALUES() {
518 return Object
.assign(
537 static get SEARCH_DEPTH() {