X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FDark.js;h=777aacc87ae3b99ca72e4708742a75ba9de6a1e5;hp=76e9462e8016b3d8322a04c548591e4be9950d7b;hb=0c3fe8a6c3e02af46e0bc646b40c1a0c420f9dcd;hpb=41c80bb63b85b2696d3925c10784c3d7bb5d2aa3 diff --git a/client/src/variants/Dark.js b/client/src/variants/Dark.js index 76e9462e..777aacc8 100644 --- a/client/src/variants/Dark.js +++ b/client/src/variants/Dark.js @@ -1,4 +1,8 @@ -class DarkRules extends ChessRules +import { ChessRules } from "@/base_rules"; +import { ArrayFun} from "@/utils/array"; +import { randInt } from "@/utils/alea"; + +export const VariantRules = class DarkRules extends ChessRules { // Standard rules, in the shadow setOtherVariables(fen) @@ -6,8 +10,8 @@ class DarkRules extends ChessRules super.setOtherVariables(fen); const [sizeX,sizeY] = [V.size.x,V.size.y]; this.enlightened = { - "w": doubleArray(sizeX,sizeY), - "b": doubleArray(sizeX,sizeY) + "w": ArrayFun.init(sizeX,sizeY), + "b": ArrayFun.init(sizeX,sizeY) }; // Setup enlightened: squares reachable by each side // (TODO: one side would be enough ?) @@ -130,10 +134,15 @@ class DarkRules extends ChessRules this.updateEnlightened(); } - checkGameEnd() - { - // No valid move: our king disappeared - return this.turn == "w" ? "0-1" : "1-0"; + getCurrentScore() + { + const color = this.turn; + const kp = this.kingPos[color]; + if (kp[0] < 0) //king disappeared + return (color == "w" ? "0-1" : "1-0"); + if (this.atLeastOneMove()) // game not over + return "*"; + return "1/2"; //no moves but kings still there (seems impossible) } static get THRESHOLD_MATE() @@ -282,6 +291,6 @@ class DarkRules extends ChessRules let candidates = [0]; for (let j=1; j