X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FThreechecks.js;h=038d2238101b378603203f852c32515dd7b6c92f;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=78aaf1f8b3c1069ca279a47f35a9bb5180f68c9c;hpb=1051336271ad4d4128ef1f66953f54973601d774;p=vchess.git diff --git a/client/src/variants/Threechecks.js b/client/src/variants/Threechecks.js index 78aaf1f8..038d2238 100644 --- a/client/src/variants/Threechecks.js +++ b/client/src/variants/Threechecks.js @@ -1,6 +1,7 @@ import { ChessRules } from "@/base_rules"; -export const VariantRules = class ThreechecksRules extends ChessRules { +export class ThreechecksRules extends ChessRules { + static IsGoodFlags(flags) { // 4 for castle + 2 for checks (0,1 or 2) return !!flags.match(/^[01]{4,4}[012]{2,2}$/); @@ -11,7 +12,7 @@ export const VariantRules = class ThreechecksRules extends ChessRules { this.checkFlags = { w: 0, b: 0 }; const flags = fenflags.substr(4); //skip first 4 digits, for castle for (let c of ["w", "b"]) { - this.checkFlags[c] = parseInt(flags.charAt(c == "w" ? 0 : 1)); + this.checkFlags[c] = parseInt(flags.charAt(c == "w" ? 0 : 1), 10); } } @@ -25,15 +26,15 @@ export const VariantRules = class ThreechecksRules extends ChessRules { } getPpath(b) { - // TODO: !!this.checkFlags condition for printDiagram, but clearly not good. + // TODO: !!this.checkFlags condition for printDiagram, but it's not good. // This is just a temporary fix. - if (b[1] == 'k' && this.checkFlags && this.checkFlags[b[0]] > 0) + if (b[1] == 'k' && !!this.checkFlags && this.checkFlags[b[0]] > 0) return "Threechecks/" + b[0] + 'k_' + this.checkFlags[b[0]]; return b; } - updateVariables(move) { - super.updateVariables(move); + postPlay(move) { + super.postPlay(move); // Does this move give check? const oppCol = this.turn; if (this.underCheck(oppCol)) @@ -47,17 +48,15 @@ export const VariantRules = class ThreechecksRules extends ChessRules { return super.getCurrentScore(); } - static GenRandInitFen() { - const randFen = ChessRules.GenRandInitFen(); + static GenRandInitFen(options) { // Add check flags (at 0) - return randFen.replace(" w 0 1111", " w 0 111100"); + return ChessRules.GenRandInitFen(options).slice(0, -2) + "00"; } getFlagsFen() { let fen = super.getFlagsFen(); // Add check flags - for (let c of ["w", "b"]) - fen += this.checkFlags[c]; + for (let c of ["w", "b"]) fen += this.checkFlags[c]; return fen; } @@ -66,4 +65,5 @@ export const VariantRules = class ThreechecksRules extends ChessRules { // Take number of checks into account return baseEval/5 - this.checkFlags["w"] + this.checkFlags["b"]; } + };