1 import ChessRules
from "/base_rules.js";
2 import {FenUtil
} from "/utils/setupPieces.js"
4 export default class CoregalRules
extends ChessRules
{
7 const s
= FenUtil
.setupPieces(
8 ['r', 'n', 'b', 'l', 'k', 'b', 'n', 'r'],
10 randomness: this.options
["randomness"],
11 between: [{p1: 'k', p2: 'r'}, {p1: 'l', p2: 'r'}],
13 // 'k' and 'l' useful only to get relative position
14 flags: ['r', 'k', 'l']
17 // Re-arrange flags: king + royal queen positions are only
18 // useful to know ordering, and thus allowed castles.
20 let relPos
= { 'w': {}, 'b': {} };
21 for (let c
of [0, 1]) {
22 const col
= (c
== 0 ? 'w' : 'b');
24 for (let i
=4*c
; i
<4*(c
+1); i
++) {
25 const pos
= parseInt(flags
.charAt(i
), 10);
26 const symb
= s
[col
][pos
];
27 if (['k', 'l'].includes(symb
)) {
29 relPos
[col
][symb
] = '0'; //left
33 relPos
[col
][symb
] = '1'; //right
36 flags
+= flags
.charAt(i
);
40 fen: s
.b
.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
41 s
.w
.join("").toUpperCase(),
43 flags: flags
+ flags
, //duplicate: one for each royal piece
45 relPos
['w']['k'] + relPos
['w']['l'] +
46 relPos
['b']['k'] + relPos
['b']['l']
53 return (Object
.assign(
59 setOtherVariables(fenParsed
, pieceArray
) {
61 //TODO: issue, relPos is set at init but doesn't persist --> see base_rules.js line 263
62 console
.log(fenParsed
);
63 super.setOtherVariables(fenParsed
, pieceArray
);
66 'k': fenParsed
.relpos
[0],
67 'l': fenParsed
.relpos
[1]
70 'k': fenParsed
.relpos
[2],
71 'l': fenParsed
.relpos
[3]
77 let res
= super.pieces();
78 res
['l'] = JSON
.parse(JSON
.stringify(res
['q']));
79 // TODO: CSS royal queen symbol (with cross?)
80 res
['l']["class"] = "royal_queen";
87 w: [0, 1].map(i
=> parseInt(fenflags
.charAt(i
), 10)),
88 b: [2, 3].map(i
=> parseInt(fenflags
.charAt(i
), 10))
91 w: [4, 5].map(i
=> parseInt(fenflags
.charAt(i
), 10)),
92 b: [6, 7].map(i
=> parseInt(fenflags
.charAt(i
), 10))
98 return ['k', 'l'].map(p
=> {
99 return ['w', 'b'].map(c
=> {
100 return this.castleFlags
[p
][c
].map(x
=> x
.toString(10)).join("");
107 p
= this.getPiece(x
, y
);
108 return ['k', 'l'].includes(p
); //no cannibal mode
111 getCastleMoves([x
, y
]) {
112 const c
= this.getColor(x
, y
),
113 p
= this.getPiece(x
, y
);
114 // Relative position of the selected piece: left or right ?
115 // If left: small castle left, large castle right.
116 // If right: usual situation.
117 const finalSquares
= [
118 this.relPos
[c
][p
] == '0' ? [1, 2] : [2, 3], //0 == left
119 this.relPos
[c
][p
] == '1' ? [6, 5] : [5, 4] //1 == right
122 super.getCastleMoves([x
, y
], finalSquares
, null, this.castleFlags
[p
][c
]);
126 updateCastleFlags(move) {
127 super.updateCastleFlags(move, this.castleFlags
['k'], 'k');
128 super.updateCastleFlags(move, this.castleFlags
['l'], 'l');