update
[xogo.git] / variants / Coregal / class.js
CommitLineData
061c078d 1import ChessRules from "/base_rules.js";
5c1c7bce 2
061c078d 3export default class CoregalRules extends ChessRules {
5c1c7bce 4
5c1c7bce
BA
5 genRandInitBaseFen() {
6 const s = FenUtil.setupPieces(
7 ['r', 'n', 'b', 'l', 'k', 'b', 'n', 'r'],
8 {
9 randomness: this.options["randomness"],
10 between: [{p1: 'k', p2: 'r'}, {p1: 'l', p2: 'r'}],
11 diffCol: ['b'],
dcfaab5d
BA
12 // 'k' and 'l' useful only to get relative position
13 flags: ['r', 'k', 'l']
5c1c7bce
BA
14 }
15 );
16 return {
17 fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
18 s.w.join("").toUpperCase(),
dcfaab5d
BA
19 // TODO: re-arrange flags, use another init variable "relPos" (in o)
20 // (maybe after FEN parsing, easier?)
21 o: {flags: s.flags + s.flags} //second set for royal queen
5c1c7bce
BA
22 };
23 }
24
25 pieces() {
26 let res = super.pieces();
27 res['l'] = JSON.parse(JSON.stringify(res['q']));
dcfaab5d 28 // TODO: CSS royal queen symbol (with cross?)
5c1c7bce
BA
29 res['l']["class"] = "royal_queen";
30 return res;
31 }
32
dcfaab5d 33 // TODO: something like that indeed (+ flags to FEN)
5c1c7bce 34 setFlags(fenflags) {
dcfaab5d
BA
35 this.castleFlags = {
36 'k': { 'w': [...Array(4)], b: [...Array(4)] },
37 'l': { 'w': [...Array(4)], b: [...Array(4)] }
38 };
5c1c7bce 39 for (let i = 0; i < 8; i++) {
dcfaab5d 40 this.castleFlags[i < 4 ? "k" : "l"][i % 4 < 2 ? "w" : "b"] =
5c1c7bce
BA
41 parseInt(fenflags.charAt(i), 10);
42 }
43 }
44
45 isKing(x, y, p) {
46 if (!p)
47 p = this.getPiece(x, y);
48 ['k', 'l'].includes(p); //no cannibal mode
49 }
50
51 getCastleMoves([x, y]) {
dcfaab5d
BA
52 const c = this.getColor(x, y),
53 p = this.getPiece(x, y);
5c1c7bce
BA
54 // Relative position of the selected piece: left or right ?
55 // If left: small castle left, large castle right.
56 // If right: usual situation.
5c1c7bce 57 const finalSquares = [
dcfaab5d
BA
58 this.relPos[c][p] == "left" ? [1, 2] : [2, 3],
59 this.relPos[c][p] == "right" ? [6, 5] : [5, 4]
5c1c7bce 60 ];
dcfaab5d
BA
61 const moves =
62 super.getCastleMoves([x, y], finalSquares, null, this.castleFlags[p]);
5c1c7bce
BA
63 return moves;
64 }
65
dcfaab5d
BA
66 // TODO: updateFlags (just pass castleFlags arg)
67
5c1c7bce 68};