Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / variants / Balaklava.js
index 3a04e1d..6a38a51 100644 (file)
@@ -1,6 +1,7 @@
 import { ChessRules } from "@/base_rules";
 
 export class BalaklavaRules extends ChessRules {
+
   static get PawnSpecs() {
     return Object.assign(
       {},
@@ -45,11 +46,10 @@ export class BalaklavaRules extends ChessRules {
     );
   }
 
-  static GenRandInitFen(randomness) {
+  static GenRandInitFen(options) {
     // No collision between 'n' and castle flags, so next replacement is fine
     return (
-      ChessRules.GenRandInitFen(randomness)
-        .replace(/n/g, 'm').replace(/N/g, 'M')
+      ChessRules.GenRandInitFen(options).replace(/n/g, 'm').replace(/N/g, 'M')
     );
   }
 
@@ -61,8 +61,19 @@ export class BalaklavaRules extends ChessRules {
         : super.getPotentialMovesFrom([x, y]);
     if (piece != V.KING) {
       // Add non-capturing knight movements
-      const lastRank = (this.turn == 'w' ? 0 : 7);
+      const color = this.turn;
+      const lastRank = (color == 'w' ? 0 : 7);
       V.steps[V.KNIGHT].forEach(step => {
+        // Pawns cannot go backward:
+        if (
+          piece == V.PAWN &&
+          (
+            (color == 'w' && step[0] > 0) ||
+            (color == 'b' && step[0] < 0)
+          )
+        ) {
+          return;
+        }
         const [i, j] = [x + step[0], y + step[1]];
         if (
           V.OnBoard(i, j) &&
@@ -78,7 +89,7 @@ export class BalaklavaRules extends ChessRules {
   }
 
   getPotentialMammothMoves(sq) {
-    return this.getSlideNJumpMoves(sq, V.steps[V.MAMMOTH], "oneStep");
+    return this.getSlideNJumpMoves(sq, V.steps[V.MAMMOTH], 1);
   }
 
   isAttacked(sq, color) {
@@ -89,10 +100,8 @@ export class BalaklavaRules extends ChessRules {
   }
 
   isAttackedByMammoth(sq, color) {
-    return (
-      this.isAttackedBySlideNJump(
-        sq, color, V.MAMMOTH, V.steps[V.MAMMOTH], "oneStep")
-    );
+    return this.isAttackedBySlideNJump(
+      sq, color, V.MAMMOTH, V.steps[V.MAMMOTH], 1);
   }
 
   static get SEARCH_DEPTH() {
@@ -106,4 +115,5 @@ export class BalaklavaRules extends ChessRules {
       ChessRules.VALUES
     );
   }
+
 };