From 76a802afb26cefa50ddd0b1aca0611761b58098f Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 9 Apr 2020 18:10:22 -0400 Subject: [PATCH] Give player all new squares when multiples are cap --- commands/games-mp/dots-and-boxes.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/commands/games-mp/dots-and-boxes.js b/commands/games-mp/dots-and-boxes.js index fed9200e..c5b835d6 100644 --- a/commands/games-mp/dots-and-boxes.js +++ b/commands/games-mp/dots-and-boxes.js @@ -99,9 +99,9 @@ module.exports = class DotsAndBoxesCommand extends Command { second = temp; } taken.push(`${first}-${second}`); - const newSquare = this.calcNewSquare(taken, owned); - if (newSquare) { - owned[newSquare] = userTurn ? 'P1' : 'P2'; + const newSquares = this.calcNewSquare(taken, owned); + if (newSquares.length) { + for (const newSquare of newSquares) owned[newSquare] = userTurn ? 'P1' : 'P2'; await msg.say(`${user}, great job! Keep going until you can\'t make any more!`); } else { userTurn = !userTurn; @@ -123,11 +123,12 @@ module.exports = class DotsAndBoxesCommand extends Command { } calcNewSquare(taken, owned) { + const newSquares = []; for (const square of squareIDs) { if (owned[square]) continue; - if (this.calcSquare(square, taken)) return square; + if (this.calcSquare(square, taken)) newSquares.push(square); } - return null; + return newSquares; } generateBoard() {