X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FTwokings.js;h=a5bd76afeb8e619a2f5e713001176ca2656beca9;hb=7e8a7ea1cb66adb4a987badfb0a3c2f99a21bd0a;hp=9e82a245d1c95a5eba0ac42ed9e8267cefb65d39;hpb=14c35dc66973e66f9d9a680abb0a35db93ee2bcb;p=vchess.git diff --git a/client/src/variants/Twokings.js b/client/src/variants/Twokings.js index 9e82a245..a5bd76af 100644 --- a/client/src/variants/Twokings.js +++ b/client/src/variants/Twokings.js @@ -2,6 +2,7 @@ import { ChessRules } from "@/base_rules"; import { CoregalRules } from "@/variants/Coregal"; export class TwokingsRules extends CoregalRules { + static get PawnSpecs() { return Object.assign( {}, @@ -21,7 +22,7 @@ export class TwokingsRules extends CoregalRules { 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; } @@ -34,9 +35,10 @@ export class TwokingsRules extends CoregalRules { } // 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 { + // 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) { @@ -80,4 +129,5 @@ export class TwokingsRules extends CoregalRules { } postUndo() {} + };