Fix typo in Fugue rules + remove Football redundant kicks
[vchess.git] / client / src / variants / Football.js
index 98e2372..d63cfee 100644 (file)
@@ -235,7 +235,7 @@ export class FootballRules extends ChessRules {
       }
     }
     const kickedFrom = x + "-" + y;
-    moves.forEach(m => m.by = kickedFrom)
+    moves.forEach(m => m.start.by = kickedFrom)
     return moves;
   }
 
@@ -282,6 +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 kicks = {};
     for (let s of steps) {
       const [i, j] = [x + s[0], y + s[1]];
       if (
@@ -289,15 +290,24 @@ export class FootballRules extends ChessRules {
         this.board[i][j] != V.EMPTY &&
         this.getColor(i, j) == c
       ) {
-        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;
+          }
+        });
       }
     }
-    // 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++) {
-        if (this.board[i][j] != V.EMPTY && this.getColor(i, j) == c) {
-          moves.push(super.getBasicMove([x, y], [i, j]));
-          if (!!computer) break outerLoop;
+    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++) {
+          if (this.board[i][j] != V.EMPTY && this.getColor(i, j) == c) {
+            moves.push(super.getBasicMove([x, y], [i, j]));
+            if (!!computer) break outerLoop;
+          }
         }
       }
     }
@@ -346,7 +356,7 @@ export class FootballRules extends ChessRules {
   filterValid(moves) {
     const L = this.kickedBy.length;
     const kb = this.kickedBy[L-1];
-    return moves.filter(m => !m.by || !kb[m.by]);
+    return moves.filter(m => !m.start.by || !kb[m.start.by]);
   }
 
   getCheckSquares() {
@@ -393,9 +403,9 @@ export class FootballRules extends ChessRules {
     }
     else {
       this.subTurn++;
-      if (!!move.by) {
+      if (!!move.start.by) {
         const L = this.kickedBy.length;
-        this.kickedBy[L-1][move.by] = true;
+        this.kickedBy[L-1][move.start.by] = true;
       }
     }
   }
@@ -409,9 +419,9 @@ export class FootballRules extends ChessRules {
     }
     else {
       this.subTurn--;
-      if (!!move.by) {
+      if (!!move.start.by) {
         const L = this.kickedBy.length;
-        delete this.kickedBy[L-1][move.by];
+        delete this.kickedBy[L-1][move.start.by];
       }
     }
     if (!passesOver) {