X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FFootball.js;h=d63cfee3ac33d84dda458bb5679e2eb918096208;hp=df46d01caf0b3140820e051f9b692554f6cdc3bf;hb=2cfc3b918bf2c6581199f9ca72b61112c35fdb15;hpb=278a28a16bfee8c64746e2ec1423259009bff886 diff --git a/client/src/variants/Football.js b/client/src/variants/Football.js index df46d01c..d63cfee3 100644 --- a/client/src/variants/Football.js +++ b/client/src/variants/Football.js @@ -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++) {