X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FWildebeest.js;h=20a32ccf5cc85653d4c6ff36d651ec40e554262f;hb=0c3fe8a6c3e02af46e0bc646b40c1a0c420f9dcd;hp=509586a9a52f60765905944dfb76816701445d2f;hpb=8d61fc4ab7373b4a576f3f9108cdf7768ae27096;p=vchess.git diff --git a/client/src/variants/Wildebeest.js b/client/src/variants/Wildebeest.js index 509586a9..20a32ccf 100644 --- a/client/src/variants/Wildebeest.js +++ b/client/src/variants/Wildebeest.js @@ -1,4 +1,8 @@ -class WildebeestRules extends ChessRules +import { ChessRules } from "@/base_rules"; +import { ArrayFun } from "@/utils/array"; +import { sample, randInt } from "@/utils/alea"; + +export const VariantRules = class WildebeestRules extends ChessRules { static getPpath(b) { @@ -211,10 +215,13 @@ class WildebeestRules extends ChessRules V.steps[V.KNIGHT].concat(V.steps[V.CAMEL]), "oneStep"); } - checkGameEnd() - { + getCurrentScore() + { + if (this.atLeastOneMove()) // game not over + return "*"; + // No valid move: game is lost (stalemate is a win) - return this.turn == "w" ? "0-1" : "1-0"; + return (this.turn == "w" ? "0-1" : "1-0"); } static get VALUES() { @@ -231,14 +238,16 @@ class WildebeestRules extends ChessRules let pieces = { "w": new Array(10), "b": new Array(10) }; for (let c of ["w","b"]) { - let positions = range(11); + let positions = ArrayFun.range(11); // Get random squares for bishops + camels (different colors) - let randIndexes = sample(range(6), 2).map(i => { return 2*i; }); + let randIndexes = sample(ArrayFun.range(6), 2) + .map(i => { return 2*i; }); let bishop1Pos = positions[randIndexes[0]]; let camel1Pos = positions[randIndexes[1]]; // The second bishop (camel) must be on a square of different color - let randIndexes_tmp = sample(range(5), 2).map(i => { return 2*i+1; }); + let randIndexes_tmp = sample(ArrayFun.range(5), 2) + .map(i => { return 2*i+1; }); let bishop2Pos = positions[randIndexes_tmp[0]]; let camel2Pos = positions[randIndexes_tmp[1]]; for (let idx of randIndexes.concat(randIndexes_tmp) @@ -247,19 +256,19 @@ class WildebeestRules extends ChessRules positions.splice(idx, 1); } - let randIndex = random(7); + let randIndex = randInt(7); let knight1Pos = positions[randIndex]; positions.splice(randIndex, 1); - randIndex = random(6); + randIndex = randInt(6); let knight2Pos = positions[randIndex]; positions.splice(randIndex, 1); - randIndex = random(5); + randIndex = randInt(5); let queenPos = positions[randIndex]; positions.splice(randIndex, 1); // Random square for wildebeest - randIndex = random(4); + randIndex = randInt(4); let wildebeestPos = positions[randIndex]; positions.splice(randIndex, 1); @@ -282,6 +291,6 @@ class WildebeestRules extends ChessRules return pieces["b"].join("") + "/ppppppppppp/11/11/11/11/11/11/PPPPPPPPPPP/" + pieces["w"].join("").toUpperCase() + - " w 1111 -"; + " w 0 1111 -"; } }