1 import { ChessRules
, Move
, PiPo
} from "@/base_rules";
2 import { ArrayFun
} from "@/utils/array";
3 import { randInt
, sample
} from "@/utils/alea";
5 export class CoregalRules
extends ChessRules
{
8 const s
= FenUtil
.setupPieces(
9 ['r', 'n', 'b', 'l', 'k', 'b', 'n', 'r'],
11 randomness: this.options
["randomness"],
12 between: [{p1: 'k', p2: 'r'}, {p1: 'l', p2: 'r'}],
14 // 'k' and 'l' useful only to get relative position
15 flags: ['r', 'k', 'l']
19 fen: s
.b
.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
20 s
.w
.join("").toUpperCase(),
21 // TODO: re-arrange flags, use another init variable "relPos" (in o)
22 // (maybe after FEN parsing, easier?)
23 o: {flags: s
.flags
+ s
.flags
} //second set for royal queen
28 let res
= super.pieces();
29 res
['l'] = JSON
.parse(JSON
.stringify(res
['q']));
30 // TODO: CSS royal queen symbol (with cross?)
31 res
['l']["class"] = "royal_queen";
35 // TODO: something like that indeed (+ flags to FEN)
38 'k': { 'w': [...Array(4)], b: [...Array(4)] },
39 'l': { 'w': [...Array(4)], b: [...Array(4)] }
41 for (let i
= 0; i
< 8; i
++) {
42 this.castleFlags
[i
< 4 ? "k" : "l"][i
% 4 < 2 ? "w" : "b"] =
43 parseInt(fenflags
.charAt(i
), 10);
49 p
= this.getPiece(x
, y
);
50 ['k', 'l'].includes(p
); //no cannibal mode
53 getCastleMoves([x
, y
]) {
54 const c
= this.getColor(x
, y
),
55 p
= this.getPiece(x
, y
);
56 // Relative position of the selected piece: left or right ?
57 // If left: small castle left, large castle right.
58 // If right: usual situation.
59 const finalSquares
= [
60 this.relPos
[c
][p
] == "left" ? [1, 2] : [2, 3],
61 this.relPos
[c
][p
] == "right" ? [6, 5] : [5, 4]
64 super.getCastleMoves([x
, y
], finalSquares
, null, this.castleFlags
[p
]);
68 // TODO: updateFlags (just pass castleFlags arg)