From 4a3cbf1d8351a20dd3293b9f463f07997886d223 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Wed, 3 Feb 2021 08:26:55 +0100
Subject: [PATCH] Fix Football: no pass move if not touching the ball

---
 client/src/variants/Football.js | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/client/src/variants/Football.js b/client/src/variants/Football.js
index 09af0f76..df46d01c 100644
--- a/client/src/variants/Football.js
+++ b/client/src/variants/Football.js
@@ -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 atLeastOnePotentialKick = false;
     for (let s of steps) {
       const [i, j] = [x + s[0], y + s[1]];
       if (
@@ -289,15 +290,18 @@ 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]));
       }
     }
-    // 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 (atLeastOnePotentialKick) {
+      // 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;
+          }
         }
       }
     }
-- 
2.44.0