From 5c672fd4d63c04e4ca71698644552b3964c4e2f1 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 9 Jan 2021 18:32:18 -0500 Subject: [PATCH] Fix --- commands/games-mp/tic-tac-toe.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/commands/games-mp/tic-tac-toe.js b/commands/games-mp/tic-tac-toe.js index d7a38e8c..14e0ea88 100644 --- a/commands/games-mp/tic-tac-toe.js +++ b/commands/games-mp/tic-tac-toe.js @@ -81,14 +81,15 @@ module.exports = class TicTacToeCommand extends Command { } sides[opponent.bot && !userTurn ? choice : Number.parseInt(choice, 10) - 1] = sign; taken.push(choice); - if (this.verifyWin(sides)) winner = userTurn ? msg.author : opponent; + const win = this.verifyWin(sides, msg.author, opponent); + if (win) winner = win; if (lastTurnTimeout) lastTurnTimeout = false; userTurn = !userTurn; } this.client.games.delete(msg.channel.id); if (winner === 'time') return msg.say('Game ended due to inactivity.'); return msg.say(stripIndents` - ${winner ? `Congrats, ${winner}!` : 'Oh... The cat won.'} + ${winner !== 'tie' ? `Congrats, ${winner}!` : 'Oh... The cat won.'} ${this.displayBoard(sides)} `); @@ -98,9 +99,11 @@ module.exports = class TicTacToeCommand extends Command { } } - verifyWin(sides) { + verifyWin(sides, player1, player2) { const evaluated = tictactoe.boardEvaluate(this.convertBoard(sides)).status; - if (evaluated === 'win' || evaluated === 'loss' || evaluated === 'tie') return true; + if (evaluated === 'win') return player1; + if (evaluated === 'loss') return player2; + if (evaluated === 'tie') return 'tie'; return false; }