3a47146b06303c1be2500af8e00bf958166abe37
1 import ChessRules
from "/base_rules.js";
2 import {FenUtil
} from "/utils/setupPieces.js"
4 export default class CwdaRules
extends ChessRules
{
8 select: ChessRules
.Options
.select
.concat([
14 { label: "Colorbound Clobberers", value: 'C' },
15 { label: "Nutty Knights", value: 'N' },
16 { label: "Remarkable Rookies", value: 'R' },
17 { label: "Fide", value: 'F' }
25 { label: "Colorbound Clobberers", value: 'C' },
26 { label: "Nutty Knights", value: 'N' },
27 { label: "Remarkable Rookies", value: 'R' },
28 { label: "Fide", value: 'F' }
32 input: ChessRules
.Options
.input
,
33 styles: ChessRules
.Options
.styles
37 static get PiecesMap() {
39 // Colorbound Clobberers
69 genRandInitBaseFen() {
70 let s
= FenUtil
.setupPieces(
71 ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
73 randomness: this.options
["randomness"],
74 between: [{p1: 'k', p2: 'r'}],
80 w: Array(8).fill('p'),
83 for (const c
of ['w', 'b']) {
84 const army
= "army" + (c
== 'w' ? "1" : "2");
85 if (this.options
[army
] != 'F') {
86 for (let obj
of [s
, pawnLines
])
87 obj
[c
] = obj
[c
].map(p
=> V
.PiecesMap
[this.options
[army
]][p
]);
91 fen: s
.b
.join("") + "/" +
92 pawnLines
['b'].join("") +
94 pawnLines
['w'].join("").toUpperCase() +
95 "/" + s
.w
.join("").toUpperCase(),
101 return Object
.assign(
102 { "armies": this.options
["army1"] + this.options
["army2"] },
107 setOtherVariables(fenParsed
) {
108 super.setOtherVariables(fenParsed
);
109 this.options
["army1"] = fenParsed
.armies
.charAt(0);
110 this.options
["army2"] = fenParsed
.armies
.charAt(1);
115 p
= this.getPiece(x
, y
);
116 return (super.isKing(x
, y
, p
) || ['a', 'e', 'm'].includes(p
));
119 // Helper to describe pieces movements
167 pieces(color
, x
, y
) {
168 const res
= super.pieces(color
, x
, y
);
169 const backward
= (color
== 'w' ? 1 : -1);
170 const forward
= -backward
;
171 return Object
.assign(
176 {steps: res
['b'].both
[0].steps
},
177 {steps: V
.steps
.d
, range: 1}
183 {steps: V
.steps
.a
, range: 1},
184 {steps: res
['r'].both
[0].steps
, range: 1}
190 {steps: V
.steps
.d
, range: 1},
191 {steps: V
.steps
.a
, range: 1},
192 {steps: res
['b'].both
[0].steps
, range: 1}
198 {steps: res
['b'].both
[0].steps
},
199 {steps: res
['n'].both
[0].steps
, range: 1}
202 'm': { "class": "c_king", moveas: 'k' },
203 'z': { "class": "c_pawn", moveas: 'p' },
207 {steps: [[0, -1], [0, 1], [color
== 'w' ? -1 : 1, 0]]},
208 {steps: [[backward
, -1], [backward
, 0], [backward
, 1]], range: 1}
214 {steps: V
.steps
.$n
, range: 1},
215 {steps: V
.steps
.f
, range: 1}
222 steps: [[0, -1], [0, 1], [backward
, -1],
223 [backward
, 0], [backward
, 1]],
227 steps: [[2*forward
, -1], [2*forward
, 1],
228 [forward
, -2], [forward
, 2]],
236 {steps: [[0, -1], [0, 1], [forward
, 0]]},
237 {steps: [[forward
, -1], [forward
, 1],
238 [backward
, -1], [backward
, 0], [backward
, 1]], range: 1},
239 {steps: [[2*forward
, -1], [2*forward
, 1],
240 [forward
, -2], [forward
, 2]], range: 1}
243 'e': { "class": "n_king", moveas: 'k' },
244 'v': { "class": "n_pawn", moveas: 'p' },
247 both: [{steps: res
['r'].both
[0].steps
, range: 4}]
252 {steps: V
.steps
.d
, range: 1},
253 {steps: V
.steps
.w
, range: 1}
259 {steps: V
.steps
.d
, range: 1},
260 {steps: V
.steps
.f
, range: 1},
261 {steps: V
.steps
.$3, range: 1}
267 {steps: res
['r'].both
[0].steps
},
268 {steps: res
['n'].both
[0].steps
, range: 1}
271 'a': { "class": "r_king", moveas: 'k' },
272 'u': { "class": "r_pawn", moveas: 'p' }
278 get pawnPromotions() {
279 // Can promote in anything from the two current armies
281 for (let army
of ["army1", "army2"]) {
282 if (army
== "army2" && this.options
["army2"] == this.options
["army1"])
284 switch (this.options
[army
]) {
286 Array
.prototype.push
.apply(promotions
, ['d', 'w', 'f', 'c']);
289 Array
.prototype.push
.apply(promotions
, ['g', 'i', 't', 'l']);
292 Array
.prototype.push
.apply(promotions
, ['s', 'y', 'h', 'o']);
295 Array
.prototype.push
.apply(promotions
, ['r', 'n', 'b', 'q']);
302 getCastleMoves([x
, y
]) {
303 const color
= this.getColor(x
, y
);
304 let finalSquares
= [ [2, 3], [this.size
.y
- 2, this.size
.y
- 3] ];
306 (color
== 'w' && this.options
["army1"] == 'C') ||
307 (color
== 'b' && this.options
["army2"] == 'C')
309 // Colorbound castle long in an unusual way:
310 finalSquares
[0] = [1, 2];
312 return super.getCastleMoves([x
, y
], finalSquares
);