Check variants. All OK except Dark (bug), Checkered (missing internal moves stack...
[vchess.git] / client / src / variants / Upsidedown.js
index 7198c0b..de72216 100644 (file)
@@ -1,4 +1,8 @@
-class UpsidedownRules extends ChessRules
+import { ChessRules } from "@/base_rules";
+import { randInt } from "@/utils/alea";
+import { ArrayFun } from "@/utils/array";
+
+export const VariantRules = class UpsidedownRules extends ChessRules
 {
        static get HasFlags() { return false; }
 
@@ -16,9 +20,9 @@ class UpsidedownRules extends ChessRules
                let pieces = { "w": new Array(8), "b": new Array(8) };
                for (let c of ["w","b"])
                {
-                       let positions = range(8);
+                       let positions = ArrayFun.range(8);
 
-                       let randIndex = random(8);
+                       let randIndex = randInt(8);
                        const kingPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
@@ -35,18 +39,18 @@ class UpsidedownRules extends ChessRules
                        positions.splice(knight1Index, 1);
 
                        // King+knight1 are on two consecutive squares: one light, one dark
-                       randIndex = 2 * random(3);
+                       randIndex = 2 * randInt(3);
                        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(4);
+                       randIndex = randInt(4);
                        const knight2Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
-                       randIndex = random(3);
+                       randIndex = randInt(3);
                        const queenPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
@@ -65,6 +69,6 @@ class UpsidedownRules extends ChessRules
                return pieces["w"].join("").toUpperCase() +
                        "/PPPPPPPP/8/8/8/8/pppppppp/" +
                        pieces["b"].join("") +
-                       " w"; //no castle, no en-passant
+                       " w 0"; //no castle, no en-passant
        }
 }