Reduce complexity

This commit is contained in:
Dragon Fire
2024-03-23 23:44:14 -04:00
parent 5cd147ad80
commit 1bcd927128
+2 -18
View File
@@ -37,7 +37,7 @@ module.exports = class TicTacToeCommand extends Command {
return msg.say('Looks like they declined...');
}
}
const sides = ['1', '2', '3', '4', '5', '6', '7', '8', '9'];
const sides = [0, 1, 2, 3, 4, 5, 6, 7, 8];
const taken = [];
let userTurn = true;
let winner = null;
@@ -48,7 +48,7 @@ module.exports = class TicTacToeCommand extends Command {
let choice;
if (opponent.bot && !userTurn) {
// eslint-disable-next-line new-cap
choice = ComputerMove(this.convertBoard(sides), { aiPlayer: 'O', huPlayer: 'X' }, 'Hard');
choice = ComputerMove(sides, { aiPlayer: 'O', huPlayer: 'X' }, 'Hard');
} else {
await msg.say(stripIndents`
${user}, which side do you pick? Type \`end\` to forfeit.
@@ -124,22 +124,6 @@ module.exports = class TicTacToeCommand extends Command {
return null;
}
convertBoard(board) {
const newBoard = [];
let num = 0;
for (const piece of board) {
if (piece === 'X') {
newBoard.push('X');
} else if (piece === 'O') {
newBoard.push('O');
} else {
newBoard.push(num);
}
num++;
}
return newBoard;
}
displayBoard(board) {
let str = '';
for (let i = 0; i < board.length; i++) {