X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FWildebeest.js;h=526da1a7f37c82b2df26518385481b74699b8c2b;hb=472c0c4f5aa29d96e080873ebfce2a04f664d852;hp=f4e3b83c5c3afc406eb01c80555d500e45bfc78b;hpb=68e19a449db7a12e0a168e99cd750d985c983ba1;p=vchess.git diff --git a/client/src/variants/Wildebeest.js b/client/src/variants/Wildebeest.js index f4e3b83c..526da1a7 100644 --- a/client/src/variants/Wildebeest.js +++ b/client/src/variants/Wildebeest.js @@ -2,7 +2,7 @@ import { ChessRules } from "@/base_rules"; import { ArrayFun } from "@/utils/array"; import { sample, randInt } from "@/utils/alea"; -export const VariantRules = class WildebeestRules extends ChessRules { +export class WildebeestRules extends ChessRules { static get size() { return { x: 10, y: 11 }; } @@ -20,7 +20,9 @@ export const VariantRules = class WildebeestRules extends ChessRules { static get steps() { return Object.assign( - ChessRules.steps, //add camel moves: + {}, + ChessRules.steps, + // Add camel moves: { c: [ [-3, -1], @@ -37,14 +39,7 @@ export const VariantRules = class WildebeestRules extends ChessRules { } static IsGoodEnpassant(enpassant) { - if (enpassant != "-") { - const squares = enpassant.split(","); - if (squares.length > 2) return false; - for (let sq of squares) { - const ep = V.SquareToCoords(sq); - if (isNaN(ep.x) || !V.OnBoard(ep)) return false; - } - } + if (enpassant != "-") return !!enpassant.match(/^([a-j][0-9]{1,2},?)+$/); return true; } @@ -160,7 +155,7 @@ export const VariantRules = class WildebeestRules extends ChessRules { // En passant const Lep = this.epSquares.length; const epSquare = this.epSquares[Lep - 1]; - if (epSquare) { + if (!!epSquare) { for (let epsq of epSquare) { // TODO: some redundant checks if (epsq.x == x + shiftX && Math.abs(epsq.y - y) == 1) { @@ -225,10 +220,7 @@ export const VariantRules = class WildebeestRules extends ChessRules { } getCurrentScore() { - if (this.atLeastOneMove()) - // game not over - return "*"; - + if (this.atLeastOneMove()) return "*"; // No valid move: game is lost (stalemate is a win) return this.turn == "w" ? "0-1" : "1-0"; } @@ -246,10 +238,14 @@ export const VariantRules = class WildebeestRules extends ChessRules { static GenRandInitFen(randomness) { if (!randomness) randomness = 2; - if (randomness == 0) - return "rnccwkqbbnr/ppppppppppp/11/11/11/11/11/11/PPPPPPPPPPP/RNBBQKWCCNR w 0 akak -"; + if (randomness == 0) { + return ( + "rnccwkqbbnr/ppppppppppp/92/92/92/92/92/92/PPPPPPPPPPP/RNBBQKWCCNR " + + "w 0 akak -" + ); + } - let pieces = { w: new Array(10), b: new Array(10) }; + let pieces = { w: new Array(11), b: new Array(11) }; let flags = ""; for (let c of ["w", "b"]) { if (c == 'b' && randomness == 1) { @@ -314,7 +310,7 @@ export const VariantRules = class WildebeestRules extends ChessRules { } return ( pieces["b"].join("") + - "/ppppppppppp/11/11/11/11/11/11/PPPPPPPPPPP/" + + "/ppppppppppp/92/92/92/92/92/92/PPPPPPPPPPP/" + pieces["w"].join("").toUpperCase() + " w 0 " + flags + " -" );