Start getPotentialMove_s() draft in Fanorona main
authorBenjamin Auder <benjamin.auder@somewhere>
Thu, 15 Oct 2026 15:32:57 +0000 (17:32 +0200)
committerBenjamin Auder <benjamin.auder@somewhere>
Thu, 15 Oct 2026 15:32:57 +0000 (17:32 +0200)
js/base_rules.js
variants/Fanorona/class.js

index dd93b81..4121c8f 100644 (file)
@@ -128,7 +128,7 @@ export default class ChessRules {
   }
 
   // Some variants do not precompute moves
-  get twoSquareMove() {
+  static get TwoSquareMove() {
     return false;
   }
 
@@ -958,7 +958,7 @@ export default class ChessRules {
             startPiece.style.opacity = "0.4";
             chessboard.style.cursor = "none";
           }
-          if (!this.twoSquareMove)
+          if (!V.TwoSquareMove)
             potentialMoves = this.getPotentialMovesFrom([x, y]);
         }
       }
@@ -987,7 +987,7 @@ export default class ChessRules {
       const cd =
         (landingElt ? this.idToCoords(landingElt.id) : undefined);
       if (cd) {
-        if (this.twoSquareMove)
+        if (V.TwoSquareMove)
           potentialMoves = this.getPotentialMove_s([x, y], [cd.x, cd.y]);
         else {
           potentialMoves =
index 1079861..338883f 100644 (file)
@@ -16,10 +16,15 @@ export default class FanoronaRules extends AbstractOnGridRules {
   get hasEnpassant() {
     return false;
   }
+
   static get HasKing() {
     return false;
   }
 
+  static get TwoSquareMove() {
+    return true;
+  }
+
   genRandInitBaseFen() {
     return {
       fen: "sssssssss/sssssssss/sSsS1sSsS/SSSSSSSSS/SSSSSSSSS",
@@ -131,10 +136,6 @@ export default class FanoronaRules extends AbstractOnGridRules {
     return ''; //never reached
   };
 
-
-// TODO: getPotentialMove_s() + pre-compute atLeastOneCapture() after each opponent move
-
-
   getPotentialMovesFrom([x, y], justCapt) {
     const oppCol = C.GetOppTurn(this.turn);
     const L = this.captures.length;
@@ -190,6 +191,24 @@ export default class FanoronaRules extends AbstractOnGridRules {
     return (!justCapt ? moves : false);
   }
 
+  getPotentialMove_s([x1, y1], [x2, y2]) {
+    if (
+      Math.abs(x2 - x1) > 1 ||
+      Math.abs(y2 - y1) > 1 ||
+      this.board[x2][y2] != ""
+    ) {
+      return [];
+    }
+    // If canCapture but nothing behind or in front, invalid
+    const step = [x2 - x1, y2 - y1];
+    if (
+      this.canCapture &&
+      ( // TODO...........
+        this.onBoard(x1 - step[0], y1 - step[1]) &&
+    let moves = [];
+
+  }
+
   atLeastOneCapture() {
     const L = this.captures.length;
     if (L > 0) {