mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Reduce complexity
This commit is contained in:
@@ -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++) {
|
||||
|
||||
Reference in New Issue
Block a user