import { CoregalRules } from "@/variants/Coregal";
export class TwokingsRules extends CoregalRules {
+
static get PawnSpecs() {
return Object.assign(
{},
if (position.length == 0) return false;
const rows = position.split("/");
if (rows.length != V.size.x) return false;
- let kings = { "w": 0, "b": 0 };
+ let kings = { 'K': 0, 'k': 0 };
for (let row of rows) {
let sumElts = 0;
for (let i = 0; i < row.length; i++) {
if (['K','k'].includes(row[i])) kings[row[i]]++;
if (V.PIECES.includes(row[i].toLowerCase())) sumElts++;
else {
- const num = parseInt(row[i]);
+ const num = parseInt(row[i], 10);
if (isNaN(num)) return false;
sumElts += num;
}
}
// Not scanning king positions. In this variant, scan the board everytime.
- scanKings(fen) {}
+ scanKings() {}
- getCheckSquares(color) {
+ getCheckSquares() {
+ const color = this.turn;
let squares = [];
const oppCol = V.GetOppCol(color);
for (let i=0; i<V.size.x; i++) {
}
static GenRandInitFen(randomness) {
- const fen = CoregalRules.GenRandInitFen(randomness);
- return fen.replace("q", "k").replace("Q", "K");
+ if (randomness == 0)
+ return "rnqkkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNQKKBNR w 0 adehadeh -";
+
+ const replaceBishop = (fen, first, ch1, ch2) => {
+ // Remove and re-add final part:
+ const suffix = fen.substr(-15);
+ fen = fen.slice(0, -15);
+ if (first) fen = fen.replace(ch1, ch2);
+ else {
+ fen =
+ fen.split("").reverse().join("")
+ .replace(ch1, ch2)
+ .split("").reverse().join("")
+ }
+ return fen + suffix;
+ };
+
+ const sameIndexReplace = (fen) => {
+ const first = (Math.random() < 0.5);
+ return replaceBishop(
+ replaceBishop(fen, first, 'B', 'Q'),
+ first,
+ 'b',
+ 'q'
+ );
+ };
+
+ const fen =
+ CoregalRules.GenRandInitFen(randomness)
+ .replace("q", "k").replace("Q", "K");
+ // Now replace a bishop by the queen,
+ // so that bishops are of different colors:
+ if (randomness == 1) return sameIndexReplace(fen);
+ const wOdd = fen.indexOf('B') % 2;
+ const bOdd = fen.indexOf('b') % 2;
+ // Since there are 7 slashes, different oddities means symmetric
+ if (wOdd != bOdd) return sameIndexReplace(fen);
+ const wFirst = (Math.random() < 0.5);
+ return replaceBishop(
+ replaceBishop(fen, wFirst, 'B', 'Q'),
+ !wFirst,
+ 'b',
+ 'q'
+ );
+ }
+
+ getPotentialQueenMoves(sq) {
+ return this.getSlideNJumpMoves(sq,
+ V.steps[V.ROOK].concat(V.steps[V.BISHOP]));
}
underCheck(color) {
}
postUndo() {}
+
};