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
{
7 //TODO: CSS royal queen symbol
10 const s
= FenUtil
.setupPieces(
11 ['r', 'n', 'b', 'l', 'k', 'b', 'n', 'r'],
13 randomness: this.options
["randomness"],
14 between: [{p1: 'k', p2: 'r'}, {p1: 'l', p2: 'r'}],
16 flags: ['r', 'k', 'l'] //TODO: add 'k' to all 'flags' calls ??!
20 fen: s
.b
.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
21 s
.w
.join("").toUpperCase(),
27 let res
= super.pieces();
28 res
['l'] = JSON
.parse(JSON
.stringify(res
['q']));
29 res
['l']["class"] = "royal_queen";
34 // white pieces positions, then black pieces positions
35 this.castleFlags
= { w: [...Array(4)], b: [...Array(4)] };
36 for (let i
= 0; i
< 8; i
++) {
37 this.castleFlags
[i
< 4 ? "w" : "b"][i
% 4] =
38 parseInt(fenflags
.charAt(i
), 10);
44 p
= this.getPiece(x
, y
);
45 ['k', 'l'].includes(p
); //no cannibal mode
48 getCastleMoves([x
, y
]) {
49 // Relative position of the selected piece: left or right ?
50 // If left: small castle left, large castle right.
51 // If right: usual situation.
52 const c
= this.getColor(x
, y
);
53 const relPos
= (this.castleFlags
[c
][1] == y
? "left" : "right");
55 const finalSquares
= [
56 relPos
== "left" ? [1, 2] : [2, 3],
57 relPos
== "right" ? [6, 5] : [5, 4]
59 const saveFlags
= JSON
.stringify(this.castleFlags
[c
]);
60 // Alter flags to follow base_rules semantic
61 this.castleFlags
[c
] = [0, 3].map(i
=> this.castleFlags
[c
][i
]);
62 const moves
= super.getCastleMoves([x
, y
], finalSquares
);
63 this.castleFlags
[c
] = JSON
.parse(saveFlags
);