Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / variants / Football.js
index df46d01..7829c2d 100644 (file)
@@ -104,13 +104,13 @@ export class FootballRules extends ChessRules {
     }
   }
 
-  static GenRandInitFen(randomness) {
-    if (randomness == 0)
+  static GenRandInitFen(options) {
+    if (options.randomness == 0)
       return "rnbq1knbr/9/9/9/4a4/9/9/9/RNBQ1KNBR w 0";
 
     let pieces = { w: new Array(8), b: new Array(8) };
     for (let c of ["w", "b"]) {
-      if (c == 'b' && randomness == 1) {
+      if (c == 'b' && options.randomness == 1) {
         pieces['b'] = pieces['w'];
         break;
       }
@@ -282,7 +282,7 @@ export class FootballRules extends ChessRules {
     const steps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]);
     const c = this.turn;
     let moves = [];
-    let atLeastOnePotentialKick = false;
+    let kicks = {};
     for (let s of steps) {
       const [i, j] = [x + s[0], y + s[1]];
       if (
@@ -290,11 +290,17 @@ export class FootballRules extends ChessRules {
         this.board[i][j] != V.EMPTY &&
         this.getColor(i, j) == c
       ) {
-        if (!atLeastOnePotentialKick) atLeastOnePotentialKick = true;
-        Array.prototype.push.apply(moves, this.tryKickFrom([i, j]));
+        const kmoves = this.tryKickFrom([i, j]);
+        kmoves.forEach(km => {
+          const key = V.CoordsToSquare(km.start) + V.CoordsToSquare(km.end);
+          if (!kicks[km]) {
+            moves.push(km);
+            kicks[km] = true;
+          }
+        });
       }
     }
-    if (atLeastOnePotentialKick) {
+    if (Object.keys(kicks).length > 0) {
       // And, always add the "end" move. For computer, keep only one
       outerLoop: for (let i=0; i < V.size.x; i++) {
         for (let j=0; j < V.size.y; j++) {
@@ -308,22 +314,8 @@ export class FootballRules extends ChessRules {
     return moves;
   }
 
-  // No captures:
-  getSlideNJumpMoves([x, y], steps, oneStep) {
-    let moves = [];
-    outerLoop: for (let step of steps) {
-      let i = x + step[0];
-      let j = y + step[1];
-      let stepCount = 1;
-      while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) {
-        moves.push(this.getBasicMove([x, y], [i, j]));
-        if (!!oneStep) continue outerLoop;
-        i += step[0];
-        j += step[1];
-        stepCount++;
-      }
-    }
-    return moves;
+  canTake() {
+    return false;
   }
 
   // Extra arg "computer" to avoid trimming all redundant pass moves: