X-Git-Url: https://git.auder.net/images/pieces/current/gitweb.js?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FCheckered.js;h=e930fb847317315be5fa0197059d2ba0b1925a28;hb=bc06c9bbc9c8ead4ae270204d10f4ff686c764a4;hp=0e4f0a0d5c5d7ffa547f3a1ebd413c9678386f5d;hpb=6808d7a16ec1e761c6a2dffec2281c96953e4d89;p=vchess.git diff --git a/client/src/variants/Checkered.js b/client/src/variants/Checkered.js index 0e4f0a0d..e930fb84 100644 --- a/client/src/variants/Checkered.js +++ b/client/src/variants/Checkered.js @@ -1,10 +1,6 @@ import { ChessRules } from "@/base_rules"; export const VariantRules = class CheckeredRules extends ChessRules { - static getPpath(b) { - return b[0] == "c" ? "Checkered/" + b : b; - } - static board2fen(b) { const checkered_codes = { p: "s", @@ -40,6 +36,10 @@ export const VariantRules = class CheckeredRules extends ChessRules { return ChessRules.PIECES.concat(["s", "t", "u", "c", "o"]); } + getPpath(b) { + return b[0] == "c" ? "Checkered/" + b : b; + } + setOtherVariables(fen) { super.setOtherVariables(fen); // Local stack of non-capturing checkered moves: @@ -74,7 +74,6 @@ export const VariantRules = class CheckeredRules extends ChessRules { w: [...Array(8).fill(true)], //pawns can move 2 squares? b: [...Array(8).fill(true)] }; - if (!fenflags) return; const flags = fenflags.substr(4); //skip first 4 digits, for castle for (let c of ["w", "b"]) { for (let i = 0; i < 8; i++) @@ -112,7 +111,8 @@ export const VariantRules = class CheckeredRules extends ChessRules { getPotentialMovesFrom([x, y]) { let standardMoves = super.getPotentialMovesFrom([x, y]); const lastRank = this.turn == "w" ? 0 : 7; - if (this.getPiece(x, y) == V.KING) return standardMoves; //king has to be treated differently (for castles) + // King has to be treated differently (for castles) + if (this.getPiece(x, y) == V.KING) return standardMoves; let moves = []; standardMoves.forEach(m => { if (m.vanish[0].p == V.PAWN) { @@ -130,7 +130,7 @@ export const VariantRules = class CheckeredRules extends ChessRules { } } if (m.vanish.length == 1) moves.push(m); - //no capture + // No capture else { // A capture occured (m.vanish.length == 2) m.appear[0].c = "c"; @@ -156,7 +156,7 @@ export const VariantRules = class CheckeredRules extends ChessRules { // Does m2 un-do m1 ? (to disallow undoing checkered moves) oppositeMoves(m1, m2) { return ( - !!m1 && + m1 && m2.appear[0].c == "c" && m2.appear.length == 1 && m2.vanish.length == 1 && @@ -170,8 +170,8 @@ export const VariantRules = class CheckeredRules extends ChessRules { filterValid(moves) { if (moves.length == 0) return []; const color = this.turn; + const L = this.cmoves.length; //at least 1: init from FEN return moves.filter(m => { - const L = this.cmoves.length; //at least 1: init from FEN if (this.oppositeMoves(this.cmoves[L - 1], m)) return false; this.play(m); const res = !this.underCheck(color);