mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-12 00:04:48 +02:00
Add previous move to c4
This commit is contained in:
@@ -77,15 +77,18 @@ module.exports = class ConnectFourCommand extends Command {
|
|||||||
let winner = null;
|
let winner = null;
|
||||||
const colLevels = [5, 5, 5, 5, 5, 5, 5];
|
const colLevels = [5, 5, 5, 5, 5, 5, 5];
|
||||||
let lastTurnTimeout = false;
|
let lastTurnTimeout = false;
|
||||||
|
let lastMove;
|
||||||
while (!winner && board.some(row => row.includes(null))) {
|
while (!winner && board.some(row => row.includes(null))) {
|
||||||
const user = userTurn ? msg.author : opponent;
|
const user = userTurn ? msg.author : opponent;
|
||||||
const sign = userTurn ? 'user' : 'oppo';
|
const sign = userTurn ? 'user' : 'oppo';
|
||||||
let i;
|
let i;
|
||||||
if (opponent.bot && !userTurn) {
|
if (opponent.bot && !userTurn) {
|
||||||
i = AIEngine.playAI('hard');
|
i = AIEngine.playAI('hard');
|
||||||
|
lastMove = i;
|
||||||
} else {
|
} else {
|
||||||
await msg.say(stripIndents`
|
await msg.say(stripIndents`
|
||||||
${user}, which column do you pick? Type \`end\` to forefeit.
|
${user}, which column do you pick? Type \`end\` to forefeit.
|
||||||
|
${AIEngine ? `I placed mine in **${lastMove}**.` : `Previous Move: **${lastMove}**`}
|
||||||
|
|
||||||
${this.displayBoard(board, playerOneEmoji, playerTwoEmoji)}
|
${this.displayBoard(board, playerOneEmoji, playerTwoEmoji)}
|
||||||
${nums.join('')}
|
${nums.join('')}
|
||||||
@@ -119,6 +122,7 @@ module.exports = class ConnectFourCommand extends Command {
|
|||||||
}
|
}
|
||||||
i = Number.parseInt(choice, 10) - 1;
|
i = Number.parseInt(choice, 10) - 1;
|
||||||
if (AIEngine) AIEngine.play(i);
|
if (AIEngine) AIEngine.play(i);
|
||||||
|
lastMove = i;
|
||||||
}
|
}
|
||||||
board[colLevels[i]][i] = sign;
|
board[colLevels[i]][i] = sign;
|
||||||
colLevels[i]--;
|
colLevels[i]--;
|
||||||
|
|||||||
Reference in New Issue
Block a user