Finish code refactoring to generate initial positions (untested)
[xogo.git] / variants / Balaklava / class.js
index e16322f..ad189cb 100644 (file)
@@ -1,4 +1,5 @@
 import ChessRules from "/base_rules.js";
+import {FenUtil} from "/utils/setupPieces.js";
 
 export default class BalaklavaRules extends ChessRules {
 
@@ -27,15 +28,17 @@ export default class BalaklavaRules extends ChessRules {
         }
       ]
     };
-    ['r', 'b', 'm', 'q'].forEach(p => res[p].moves = knightSpec.moves);
+    ['p', 'r', 'b', 'm', 'q'].forEach(p => res[p].moves = knightSpec.moves);
     return res;
   }
 
   genRandInitBaseFen() {
-    const baseFen = super.genRandInitBaseFen();
+    const s = FenUtil.setupPieces(
+      ['r', 'm', 'b', 'q', 'k', 'b', 'm', 'r'], {diffCol: ['b']});
     return {
-      fen: baseFen.fen.replace(/n/g, 'm').replace(/N/g, 'M'),
-      o: baseFen.o
+      fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
+           s.w.join("").toUpperCase(),
+      o: {}
     };
   }
 
@@ -44,12 +47,16 @@ export default class BalaklavaRules extends ChessRules {
       return [];
     const color = moves[0].vanish[0].c;
     const lastRank = (color == 'w' ? 0 : this.size.x - 1);
+    const forward = (color == 'w' ? -1 : 1);
     const noKnightPromotions = moves.filter(m => {
       return (
-        m.end.x != lastRank ||
+        (m.end.x - m.start.x) * forward > 0 &&
         (
-          Math.abs(m.start.x - m.end.x) <= 1 &&
-          Math.abs(m.start.y - m.end.y) <= 1
+          m.end.x != lastRank ||
+          (
+            Math.abs(m.start.x - m.end.x) <= 1 &&
+            Math.abs(m.start.y - m.end.y) <= 1
+          )
         )
       );
     });