X-Git-Url: https://git.auder.net/js/rpsls.js?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Fvariants%2FWildebeest.js;h=7a9e35c45239f82baf1957fd98edecaffa3bf21d;hb=f52671e5b5b50b1421474f27dc9c18f701b559f3;hp=5bb50e812ba46bfc77a327917e09ed43c69ac08d;hpb=bb688df52df0713aba7b2c1c068614544f5ae96d;p=vchess.git diff --git a/client/src/variants/Wildebeest.js b/client/src/variants/Wildebeest.js index 5bb50e81..7a9e35c4 100644 --- a/client/src/variants/Wildebeest.js +++ b/client/src/variants/Wildebeest.js @@ -3,6 +3,7 @@ import { ArrayFun } from "@/utils/array"; import { sample, randInt } from "@/utils/alea"; export class WildebeestRules extends ChessRules { + static get size() { return { x: 10, y: 11 }; } @@ -20,7 +21,9 @@ export 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 +40,7 @@ export 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,11 +156,11 @@ export 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) { - var enpassantMove = this.getBasicMove([x, y], [epsq.x, epsq.y]); + let enpassantMove = this.getBasicMove([x, y], [epsq.x, epsq.y]); // WARNING: the captured pawn may be diagonally behind us, // if it's a 3-squares jump and we take on 1st passing square const px = this.board[x][epsq.y] != V.EMPTY ? x : x - shiftX; @@ -182,8 +178,6 @@ export class WildebeestRules extends ChessRules { return moves; } - // TODO: wildebeest castle - getPotentialCamelMoves(sq) { return this.getSlideNJumpMoves(sq, V.steps[V.CAMEL], "oneStep"); } @@ -243,10 +237,14 @@ export 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) { @@ -311,9 +309,10 @@ export 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 + " -" ); } + };