X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAntiking.js;h=7b57e74aecc4017a2040fa1b40ce63bca0733f8f;hb=0c3fe8a6c3e02af46e0bc646b40c1a0c420f9dcd;hp=890da5800e337a480f1cd1d426c66d84e48bdd70;hpb=8d61fc4ab7373b4a576f3f9108cdf7768ae27096;p=vchess.git diff --git a/client/src/variants/Antiking.js b/client/src/variants/Antiking.js index 890da580..7b57e74a 100644 --- a/client/src/variants/Antiking.js +++ b/client/src/variants/Antiking.js @@ -1,4 +1,8 @@ -class AntikingRules extends ChessRules +import { ChessRules } from "@/base_rules"; +import { ArrayFun} from "@/utils/array"; +import { randInt } from "@/utils/alea"; + +export const VariantRules = class AntikingRules extends ChessRules { static getPpath(b) { @@ -125,9 +129,12 @@ class AntikingRules extends ChessRules this.antikingPos[c] = [move.start.x, move.start.y]; } - checkGameEnd() + getCurrentScore() { - const color = this.turn; + if (this.atLeastOneMove()) // game not over + return "*"; + + const color = this.turn; const oppCol = V.GetOppCol(color); if (!this.isAttacked(this.kingPos[color], [oppCol]) && this.isAttacked(this.antikingPos[color], [oppCol])) @@ -150,25 +157,25 @@ class AntikingRules extends ChessRules let antikingPos = { "w": -1, "b": -1 }; for (let c of ["w","b"]) { - let positions = range(8); + let positions = ArrayFun.range(8); // Get random squares for bishops, but avoid corners; because, // if an antiking blocks a cornered bishop, it can never be checkmated - let randIndex = 2 * random(1,4); + let randIndex = 2 * randInt(1,4); const bishop1Pos = positions[randIndex]; - let randIndex_tmp = 2 * random(3) + 1; + let randIndex_tmp = 2 * randInt(3) + 1; const bishop2Pos = positions[randIndex_tmp]; positions.splice(Math.max(randIndex,randIndex_tmp), 1); positions.splice(Math.min(randIndex,randIndex_tmp), 1); - randIndex = random(6); + randIndex = randInt(6); const knight1Pos = positions[randIndex]; positions.splice(randIndex, 1); - randIndex = random(5); + randIndex = randInt(5); const knight2Pos = positions[randIndex]; positions.splice(randIndex, 1); - randIndex = random(4); + randIndex = randInt(4); const queenPos = positions[randIndex]; positions.splice(randIndex, 1); @@ -177,7 +184,7 @@ class AntikingRules extends ChessRules const rook2Pos = positions[2]; // Random squares for antikings - antikingPos[c] = random(8); + antikingPos[c] = randInt(8); pieces[c][rook1Pos] = 'r'; pieces[c][knight1Pos] = 'n'; @@ -195,6 +202,6 @@ class AntikingRules extends ChessRules return pieces["b"].join("") + "/" + ranks23_black + "/8/8/" + ranks23_white + "/" + pieces["w"].join("").toUpperCase() + - " w 1111 -"; + " w 0 1111 -"; } }