New variant idea
[xogo.git] / variants / Align4 / class.js
index f603c51..f5b8f83 100644 (file)
@@ -13,6 +13,14 @@ export default class Align4Rules extends ChessRules {
           {label: "Random", value: 1}
         ]
       }],
+      input: [
+        {
+          label: "Pawn first",
+          variable: "pawnfirst",
+          type: "checkbox",
+          defaut: false
+        }
+      ],
       styles: ["atomic", "capture", "cylinder"]
     };
   }
@@ -24,13 +32,12 @@ export default class Align4Rules extends ChessRules {
     return false;
   }
 
-  genRandInitFen(seed) {
-    const baseFen = super.genRandInitFen(seed);
-    const fen = baseFen.replace("rnbqkbnr/pppppppp", "4k3/8");
-    const fenParts = fen.split(" ");
-    let others = JSON.parse(fenParts[3]);
-    others["flags"] = others["flags"].substr(0, 2) + "88";
-    return fenParts.slice(0, 3).join(" ") + " " + JSON.stringify(others);
+  genRandInitBaseFen() {
+    let baseFen = super.genRandInitBaseFen();
+    return {
+      fen: baseFen.fen.replace("rnbqkbnr/pppppppp", "4k3/8"),
+      o: {flags: baseFen.o.flags.substr(0, 2) + "88"}
+    };
   }
 
   initReserves() {
@@ -40,8 +47,19 @@ export default class Align4Rules extends ChessRules {
   // Just do not update any reserve (infinite supply)
   updateReserve() {}
 
-  getCurrentScore(move) {
-    const score = super.getCurrentScore(move);
+  canDrop([c, p], [i, j]) {
+    return (
+      this.board[i][j] == "" &&
+      (
+        p != "p" || this.options["pawnfirst"] ||
+        (c == 'w' && i < this.size.x - 1) ||
+        (c == 'b' && i > 0)
+      )
+    );
+  }
+
+  getCurrentScore(move_s) {
+    const score = super.getCurrentScore(move_s);
     if (score != "*")
       return score;
     // Check pawns connection: