mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 18:05:01 +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...');
|
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 = [];
|
const taken = [];
|
||||||
let userTurn = true;
|
let userTurn = true;
|
||||||
let winner = null;
|
let winner = null;
|
||||||
@@ -48,7 +48,7 @@ module.exports = class TicTacToeCommand extends Command {
|
|||||||
let choice;
|
let choice;
|
||||||
if (opponent.bot && !userTurn) {
|
if (opponent.bot && !userTurn) {
|
||||||
// eslint-disable-next-line new-cap
|
// 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 {
|
} else {
|
||||||
await msg.say(stripIndents`
|
await msg.say(stripIndents`
|
||||||
${user}, which side do you pick? Type \`end\` to forfeit.
|
${user}, which side do you pick? Type \`end\` to forfeit.
|
||||||
@@ -124,22 +124,6 @@ module.exports = class TicTacToeCommand extends Command {
|
|||||||
return null;
|
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) {
|
displayBoard(board) {
|
||||||
let str = '';
|
let str = '';
|
||||||
for (let i = 0; i < board.length; i++) {
|
for (let i = 0; i < board.length; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user