Fix FenUtil.setupPieces and Antiking variants
[xogo.git] / variants / Chakart / class.js
index d804548..4c55220 100644 (file)
@@ -1,7 +1,7 @@
 import ChessRules from "/base_rules.js";
-import GiveawayRules from "/variants/Giveaway/class.js";
 import {ArrayFun} from "/utils/array.js";
 import {Random} from "/utils/alea.js";
+import {FenUtil} from "/utils/setupPieces.js";
 import PiPo from "/utils/PiPo.js";
 import Move from "/utils/Move.js";
 
@@ -116,7 +116,6 @@ export default class ChakartRules extends ChessRules {
       {
         'y': {
           // Virtual piece for "king remote shell captures"
-          moves: [],
           attack: [
             {
               steps: [
@@ -132,11 +131,18 @@ export default class ChakartRules extends ChessRules {
   }
 
   genRandInitBaseFen() {
-    const options = Object.assign({mode: "suicide"}, this.options);
-    const gr = new GiveawayRules({options: options, genFenOnly: true});
-    let res = gr.genRandInitBaseFen();
-    res.o["flags"] = "1111"; //Peach + Mario flags
-    return res;
+    const s = FenUtil.setupPieces(
+      ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
+      {
+        randomness: this.options["randomness"],
+        diffCol: ['b']
+      }
+    );
+    return {
+      fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
+           s.w.join("").toUpperCase(),
+      o: {flags: "1111"} //Peach + Mario
+    };
   }
 
   fen2board(f) {
@@ -312,7 +318,7 @@ export default class ChakartRules extends ChessRules {
         moves.push(this.getBasicMove([x, y], [x + shiftX, nextY]));
       }
     }
-    this.pawnPostProcess(moves, color, oppCol);
+    moves = super.pawnPostProcess(moves, color, oppCol);
     // Add mushroom on before-last square (+ potential segments)
     moves.forEach(m => {
       let [mx, my] = [x, y];
@@ -472,8 +478,7 @@ export default class ChakartRules extends ChessRules {
       )
     ) {
       // "Forgotten" promotion, which occurred after some effect
-      let moves = [move];
-      super.pawnPostProcess(moves, color, C.GetOppCol(color));
+      let moves = super.pawnPostProcess([move], color, C.GetOppCol(color));
       super.showChoices(moves, r);
     }
     else
@@ -481,6 +486,8 @@ export default class ChakartRules extends ChessRules {
   }
 
   computeNextMove(move) {
+    if (move.koopa)
+      return null;
     // Set potential random effects, so that play() is deterministic
     // from opponent viewpoint:
     const endPiece = this.getPiece(move.end.x, move.end.y);
@@ -641,6 +648,7 @@ export default class ChakartRules extends ChessRules {
             p: this.getPiece(move.start.x, move.start.y)
           }));
         }
+        em.koopa = true; //avoid applying effect
         break;
       case "chomp":
         // Eat piece