mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-27 14:18:36 +02:00
Reduce Minesweeper Command Complexity
This commit is contained in:
@@ -96,71 +96,24 @@ module.exports = class MinesweeperCommand extends Command {
|
|||||||
await msg.say('You cannot flag a range.');
|
await msg.say('You cannot flag a range.');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* eslint-disable max-depth */
|
|
||||||
if (xRange) {
|
if (xRange) {
|
||||||
for (let i = x; i <= xRange; i++) {
|
for (let i = x; i <= xRange; i++) {
|
||||||
if (flag) {
|
const keepGoing = await this.runResult(msg, game, i, y, flag, flagged, win);
|
||||||
if (flagged.includes(`${i - 1},${y - 1}`)) {
|
if (keepGoing === false) break;
|
||||||
removeFromArray(flagged, `${i - 1},${y - 1}`);
|
if (keepGoing === null) continue;
|
||||||
} else {
|
|
||||||
flagged.push(`${i - 1},${y - 1}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (flagged.includes(`${i - 1},${y - 1}`)) {
|
|
||||||
await msg.say(`Are you sure you want to check (${x - 1}, ${y - 1})? You have it flagged.`);
|
|
||||||
const verification = await verify(msg.channel, msg.author);
|
|
||||||
if (!verification) {
|
|
||||||
await msg.say('Okay, the spot will remain unchecked.');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
game.CheckCell(i - 1, y - 1); // eslint-disable-line new-cap
|
|
||||||
if (win === true || win === false) break;
|
|
||||||
}
|
|
||||||
if (win === true || win === false) break;
|
|
||||||
}
|
}
|
||||||
} else if (yRange) {
|
} else if (yRange) {
|
||||||
for (let i = y; i <= yRange; i++) {
|
for (let i = y; i <= yRange; i++) {
|
||||||
if (flag) {
|
const keepGoing = await this.runResult(msg, game, x, i, flag, flagged, win);
|
||||||
if (flagged.includes(`${x - 1},${i - 1}`)) {
|
if (keepGoing === false) break;
|
||||||
removeFromArray(flagged, `${x - 1},${i - 1}`);
|
if (keepGoing === null) continue;
|
||||||
} else {
|
|
||||||
flagged.push(`${x - 1},${i - 1}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (flagged.includes(`${x - 1},${i - 1}`)) {
|
|
||||||
await msg.say(`Are you sure you want to check (${x - 1}, ${y - 1})? You have it flagged.`);
|
|
||||||
const verification = await verify(msg.channel, msg.author);
|
|
||||||
if (!verification) {
|
|
||||||
await msg.say('Okay, the spot will remain unchecked.');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
game.CheckCell(x - 1, i - 1); // eslint-disable-line new-cap
|
|
||||||
if (win === true || win === false) break;
|
|
||||||
}
|
|
||||||
if (win === true || win === false) break;
|
|
||||||
}
|
|
||||||
} else if (flag) {
|
|
||||||
if (flagged.includes(`${x - 1},${y - 1}`)) {
|
|
||||||
removeFromArray(flagged, `${x - 1},${y - 1}`);
|
|
||||||
} else {
|
|
||||||
flagged.push(`${x - 1},${y - 1}`);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (flagged.includes(`${x - 1},${y - 1}`)) {
|
const keepGoing = await this.runResult(msg, game, x, y, flag, flagged, win);
|
||||||
await msg.say('Are you sure you want to check this spot? You have it flagged.');
|
if (keepGoing === false) break;
|
||||||
const verification = await verify(msg.channel, msg.author);
|
if (keepGoing === null) continue;
|
||||||
if (!verification) {
|
|
||||||
await msg.say('Okay, the spot will remain unchecked.');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
game.CheckCell(x - 1, y - 1); // eslint-disable-line new-cap
|
|
||||||
if (win === true || win === false) break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* eslint-enable max-depth */
|
|
||||||
const newScore = Date.now() - startTime;
|
const newScore = Date.now() - startTime;
|
||||||
const highScoreGet = await this.client.redis.get(`minesweeper-${size}`);
|
const highScoreGet = await this.client.redis.get(`minesweeper-${size}`);
|
||||||
const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null;
|
const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null;
|
||||||
@@ -187,6 +140,29 @@ module.exports = class MinesweeperCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async runResult(msg, game, x, y, flag, flagged, win) {
|
||||||
|
if (flag) {
|
||||||
|
if (flagged.includes(`${x - 1},${y - 1}`)) {
|
||||||
|
removeFromArray(flagged, `${x - 1},${y - 1}`);
|
||||||
|
} else {
|
||||||
|
flagged.push(`${x - 1},${y - 1}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (flagged.includes(`${x - 1},${y - 1}`)) {
|
||||||
|
await msg.say(`Are you sure you want to check (${x - 1}, ${y - 1})? You have it flagged.`);
|
||||||
|
const verification = await verify(msg.channel, msg.author);
|
||||||
|
if (!verification) {
|
||||||
|
await msg.say('Okay, the spot will remain unchecked.');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
game.CheckCell(x - 1, y - 1); // eslint-disable-line new-cap
|
||||||
|
if (win === true || win === false) return false;
|
||||||
|
}
|
||||||
|
if (win === true || win === false) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
displayBoard(board, mask, flagged, cheatMode = false) {
|
displayBoard(board, mask, flagged, cheatMode = false) {
|
||||||
let str = '';
|
let str = '';
|
||||||
str += '⬛';
|
str += '⬛';
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "129.4.0",
|
"version": "129.4.1",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user