From: Benjamin Auder Date: Wed, 3 Feb 2021 07:26:55 +0000 (+0100) Subject: Fix Football: no pass move if not touching the ball X-Git-Url: https://git.auder.net/assets/current/%7B%7B%20path%28%27mixstore_store_package_view%27%2C%20%7B%20id:%20key%20%7D%29%20%7D%7D?a=commitdiff_plain;ds=sidebyside;h=4a3cbf1d8351a20dd3293b9f463f07997886d223;p=vchess.git Fix Football: no pass move if not touching the ball --- 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; + } } } }