mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-20 21:44:48 +02:00
Fix
This commit is contained in:
@@ -81,14 +81,15 @@ module.exports = class TicTacToeCommand extends Command {
|
|||||||
}
|
}
|
||||||
sides[opponent.bot && !userTurn ? choice : Number.parseInt(choice, 10) - 1] = sign;
|
sides[opponent.bot && !userTurn ? choice : Number.parseInt(choice, 10) - 1] = sign;
|
||||||
taken.push(choice);
|
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;
|
if (lastTurnTimeout) lastTurnTimeout = false;
|
||||||
userTurn = !userTurn;
|
userTurn = !userTurn;
|
||||||
}
|
}
|
||||||
this.client.games.delete(msg.channel.id);
|
this.client.games.delete(msg.channel.id);
|
||||||
if (winner === 'time') return msg.say('Game ended due to inactivity.');
|
if (winner === 'time') return msg.say('Game ended due to inactivity.');
|
||||||
return msg.say(stripIndents`
|
return msg.say(stripIndents`
|
||||||
${winner ? `Congrats, ${winner}!` : 'Oh... The cat won.'}
|
${winner !== 'tie' ? `Congrats, ${winner}!` : 'Oh... The cat won.'}
|
||||||
|
|
||||||
${this.displayBoard(sides)}
|
${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;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user