Cleaner fen generation + first draft of Apocalypse + a few fixes
[xogo.git] / variants / Antiking1 / class.js
index f8406b7..9d981e8 100644 (file)
@@ -1,30 +1,14 @@
 import ChessRules from "/base_rules.js";
-import AbstractAntikingRules from "/variants/AbstractAntiking.js";
+import AbstractAntikingRules from "/variants/_Antiking/class.js";
 
-export class Antiking1Rules extends AbstractAntikingRules {
-
-  static get Options() {
-    return {
-      styles: [
-        "atomic",
-        "balance",
-        "cannibal",
-        "capture",
-        "crazyhouse",
-        "doublemove",
-        "madrasi",
-        "progressive",
-        "recycle",
-        "rifle",
-        "teleport",
-        "zen"
-      ]
-    };
-  }
+export default class Antiking1Rules extends AbstractAntikingRules {
 
   get hasCastle() {
     return false;
   }
+  get hasEnpassant() {
+    return false;
+  }
 
   pieces(color, x, y) {
     const pawnShift = (color == "w" ? -1 : 1);
@@ -44,20 +28,20 @@ export class Antiking1Rules extends AbstractAntikingRules {
     return res;
   }
 
-  genRandInitFen() {
+  genRandInitBaseFen() {
     // Always deterministic setup
-    return (
-      '2prbkqA/2p1nnbr/2pppppp/8/8/PPPPPP2/RBNN1P2/aQKBRP2 w 0 ' +
-      '{"flags":"KAka"}'
-    );
+    return {
+      fen: "2prbkqA/2p1nnbr/2pppppp/8/8/PPPPPP2/RBNN1P2/aQKBRP2 w 0",
+      o: {"flags": "KAka"}
+    };
   }
 
   // (Anti)King flags at 1 (true) if they can knight-jump
   setFlags(fenflags) {
     this.kingFlags = { w: {}, b: {} };
-    for (let i=0; i<fenFlags.length; i++) {
-      const white = fenFlags.charCodeAt(i) <= 90;
-      const curChar = fenFlags.charCodeAt(i).toLowerCase();
+    for (let i=0; i<fenflags.length; i++) {
+      const white = fenflags.charCodeAt(i) <= 90;
+      const curChar = fenflags.charAt(i).toLowerCase();
       this.kingFlags[white ? 'w' : 'b'][curChar] = true;
     }
   }
@@ -65,7 +49,10 @@ export class Antiking1Rules extends AbstractAntikingRules {
   getFlagsFen() {
     return (
       Array.prototype.concat.apply(
-        ['w', 'b'].map(c => Object.keys(this.kingFlags[c]))
+        ['w', 'b'].map(c => {
+          const res = Object.keys(this.kingFlags[c]).join("");
+          return (c == 'w' ? res.toUpperCase() : res);
+        })
       ).join("")
     );
   }
@@ -73,11 +60,11 @@ export class Antiking1Rules extends AbstractAntikingRules {
   getPotentialMovesFrom([x, y]) {
     const color = this.turn;
     let moves = super.getPotentialMovesFrom([x, y]);
-    if (this.kingFlags[color][piece]) {
+    if (this.kingFlags[color][this.getPiece(x, y)]) {
       // Allow knight jump (king or antiking)
       const knightMoves = super.getPotentialMovesOf('n', [x, y]);
       // Remove captures (TODO: could be done more efficiently...)
-      moves = moves.concat(knightJumps.filter(m => m.vanish.length == 1));
+      moves = moves.concat(knightMoves.filter(m => m.vanish.length == 1));
     }
     return moves;
   }