X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FCheckered.js;h=0e089f38048f36b4eab74212e335da00f53f7bc0;hp=1e42d9955d84f744994c1e72ff0ec3d9f601d2f6;hb=3a2a7b5fd3c6bfd0752838094c27e1fb6172d109;hpb=afbf3ca7151ef15a9e579b0f913683ab212396c4 diff --git a/client/src/variants/Checkered.js b/client/src/variants/Checkered.js index 1e42d995..0e089f38 100644 --- a/client/src/variants/Checkered.js +++ b/client/src/variants/Checkered.js @@ -44,7 +44,7 @@ export const VariantRules = class CheckeredRules extends ChessRules { super.setOtherVariables(fen); // Local stack of non-capturing checkered moves: this.cmoves = []; - const cmove = fen.split(" ")[5]; + const cmove = V.ParseFen(fen).cmove; if (cmove == "-") this.cmoves.push(null); else { this.cmoves.push({ @@ -65,7 +65,7 @@ export const VariantRules = class CheckeredRules extends ChessRules { static IsGoodFlags(flags) { // 4 for castle + 16 for pawns - return !!flags.match(/^[01]{20,20}$/); + return !!flags.match(/^[a-z]{4,4}[01]{16,16}$/); } setFlags(fenflags) { @@ -74,7 +74,7 @@ export const VariantRules = class CheckeredRules extends ChessRules { w: [...Array(8).fill(true)], //pawns can move 2 squares? b: [...Array(8).fill(true)] }; - const flags = fenflags.substr(4); //skip first 4 digits, for castle + const flags = fenflags.substr(4); //skip first 4 letters, for castle for (let c of ["w", "b"]) { for (let i = 0; i < 8; i++) this.pawnFlags[c][i] = flags.charAt((c == "w" ? 0 : 8) + i) == "1"; @@ -331,12 +331,17 @@ export const VariantRules = class CheckeredRules extends ChessRules { return res; } - updateVariables(move) { - super.updateVariables(move); + postPlay(move) { + super.postPlay(move); // Does this move turn off a 2-squares pawn flag? - const secondRank = [1, 6]; - if (secondRank.includes(move.start.x) && move.vanish[0].p == V.PAWN) + if ([1, 6].includes(move.start.x) && move.vanish[0].p == V.PAWN) this.pawnFlags[move.start.x == 6 ? "w" : "b"][move.start.y] = false; + this.cmoves.push(this.getCmove(move)); + } + + postUndo(move) { + super.postUndo(move); + this.cmoves.pop(); } getCurrentScore() { @@ -374,9 +379,9 @@ export const VariantRules = class CheckeredRules extends ChessRules { } static GenRandInitFen(randomness) { + // Add 16 pawns flags + empty cmove: return ChessRules.GenRandInitFen(randomness) - // Add 16 pawns flags + empty cmove: - .replace(" w 0 1111", " w 0 11111111111111111111 -"); + .slice(0, -2) + "1111111111111111 - -"; } static ParseFen(fen) { @@ -403,17 +408,6 @@ export const VariantRules = class CheckeredRules extends ChessRules { return fen; } - // TODO (design): this cmove update here or in (un)updateVariables ? - play(move) { - this.cmoves.push(this.getCmove(move)); - super.play(move); - } - - undo(move) { - this.cmoves.pop(); - super.undo(move); - } - static get SEARCH_DEPTH() { return 2; }