Small refactor main
authorBenjamin Auder <benjamin.auder@somewhere>
Fri, 12 Jun 2026 13:44:11 +0000 (15:44 +0200)
committerBenjamin Auder <benjamin.auder@somewhere>
Fri, 12 Jun 2026 13:44:11 +0000 (15:44 +0200)
js/base_rules.js
utils/TargetObj.js [new file with mode: 0644]
utils/array.js
variants/Absorption/class.js
variants/Alice/class.js
variants/Apocalypse/class.js
variants/Arena/class.js
variants/Checkless/class.js
variants/Recycle/class.js

index a91c2a3..749b65c 100644 (file)
@@ -3,21 +3,7 @@ import {ArrayFun} from "/utils/array.js";
 import {FenUtil} from "/utils/setupPieces.js";
 import PiPo from "/utils/PiPo.js";
 import Move from "/utils/Move.js";
-
-// Helper class for move animation
-class TargetObj {
-
-  constructor(callOnComplete) {
-    this.value = 0;
-    this.target = 0;
-    this.callOnComplete = callOnComplete;
-  }
-  increment() {
-    if (++this.value == this.target)
-      this.callOnComplete();
-  }
-
-};
+import TargetObj from "/utils/TargetObj.js";
 
 // NOTE: x coords: top to bottom (white perspective); y: left to right
 // NOTE: ChessRules is aliased as window.C, and variants as window.V
diff --git a/utils/TargetObj.js b/utils/TargetObj.js
new file mode 100644 (file)
index 0000000..7238970
--- /dev/null
@@ -0,0 +1,15 @@
+// Helper class for move animation
+export default class TargetObj {
+
+  constructor(callOnComplete) {
+    this.value = 0;
+    this.target = 0;
+    this.callOnComplete = callOnComplete;
+  }
+  increment() {
+    if (++this.value == this.target)
+      this.callOnComplete();
+  }
+
+};
+
index af8462e..dc74949 100644 (file)
@@ -13,14 +13,4 @@ export const ArrayFun = {
     return [...Array(max - min).keys()].map(k => k + min);
   },
 
-  toObject: function(keys, values) {
-    if (!Array.isArray(values))
-      // Second argument is a scalar
-      values = Array(keys.length).fill(values);
-    return (
-      ArrayFun.range(keys.length)
-      .reduce((acc, curr) => (acc[keys[curr]] = values[curr], acc), {})
-    );
-  }
-
 };
index b29d864..097ee43 100644 (file)
@@ -14,7 +14,6 @@ export default class AbsorptionRules extends ChessRules {
         "doublemove",
         "progressive",
         "recycle",
-        //"rifle", //TODO
         "teleport",
         "zen"
       ]
@@ -120,7 +119,6 @@ export default class AbsorptionRules extends ChessRules {
     return V.MergeComposed[[p1, p2].sort().join("")];
   }
 
-  // TODO: interaction with rifle ?
   postProcessPotentialMoves(moves) {
     // Filter out capturing promotions (except one),
     // because they are all the same.
index a9a9ad1..3151cad 100644 (file)
@@ -11,7 +11,6 @@ export default class AliceRules extends ChessRules {
         "balance",
         "capture",
         "cylinder",
-        "dark",
         "doublemove",
         "progressive",
         "zen"
index e9c14c3..844e17e 100644 (file)
@@ -35,10 +35,10 @@ export default class ApocalypseRules extends ChessRules {
       ? JSON.parse(fenParsed.whiteMove)
       : [];
     this.firstMove = null; //used if black turn pawn relocation
-    this.penalties = ArrayFun.toObject(
-      ['w', 'b'],
-      [0, 1].map(i => parseInt(fenParsed.penalties.charAt(i), 10))
-    );
+    this.penalties = {
+      'w': parseInt(fenParsed.penalties.charAt(0), 10),
+      'b': parseInt(fenParsed.penalties.charAt(1), 10)
+    };
   }
 
   genRandInitBaseFen() {
index 035aee7..93493ab 100644 (file)
@@ -3,7 +3,11 @@ import ChessRules from "/js/base_rules.js";
 export default class ArenaRules extends ChessRules {
 
   static get Options() {
-    return {}; //TODO
+    return {
+      select: C.Options.select,
+      input: [],
+      styles: ["atomic", "cannibal", "capture", "cylinder", "zen"]
+    };
   }
 
   get hasFlags() {
index bb6324c..09eb0b4 100644 (file)
@@ -2,6 +2,15 @@ import ChessRules from "/js/base_rules.js";
 
 export default class ChecklessRules extends ChessRules {
 
+  static get Options() {
+    return {
+      select: C.Options.select,
+      input: C.Options.input.filter(o => o.variable == "pawnfall"),
+      styles: ["cannibal", "capture", "crazyhouse", "cylinder", "madrasi",
+               "progressive", "recycle", "rifle", "teleport", "zen"]
+    };
+  }
+
   // Cannot use super.atLeastOneMove: lead to infinite recursion
   atLeastOneMove_aux(kingPos, oppKingPos, color, oppCol) {
     for (let i = 0; i < this.size.x; i++) {
index a8c27db..e5d6cb2 100644 (file)
@@ -5,20 +5,7 @@ export default class RecycleRules extends ChessRules {
   static get Options() {
     return {
       select: C.Options.select,
-      input: [
-        {
-          label: "Capture king",
-          variable: "taking",
-          type: "checkbox",
-          defaut: false
-        },
-        {
-          label: "Falling pawn",
-          variable: "pawnfall",
-          type: "checkbox",
-          defaut: true
-        }
-      ],
+      input: C.Options.input,
       styles: C.Options.styles.filter(s => s != "recycle")
     };
   }