+ // Re-arrange flags: king + royal queen positions are only
+ // useful to know ordering, and thus allowed castles.
+ let flags = "";
+ let relPos = { 'w': {}, 'b': {} };
+ for (let c of [0, 1]) {
+ const col = (c == 0 ? 'w' : 'b');
+ let first = "";
+ for (let i=4*c; i<4*(c+1); i++) {
+ const pos = parseInt(flags.charAt(i), 10);
+ const symb = s[col][pos];
+ if (['k', 'l'].includes(symb)) {
+ if (!first) {
+ relPos[col][symb] = '0'; //left
+ first = symb;
+ }
+ else
+ relPos[col][symb] = '1'; //right
+ }
+ else
+ flags += flags.charAt(i);
+ }
+ }