jozsefsallai / discord.js-minesweeper

Generate Minesweeper mine fields using Discord's spoiler tags.
MIT License
16 stars 4 forks source link

Might have some algo issue #17

Closed adan-ea closed 2 years ago

adan-ea commented 2 years ago

When i generate a minesweeper it just goes this way for some reason. image

How i generate the minesweeper in my code (i use discord akairo, it might break something ?):

const minesweeper = new Minesweeper({
            rows: rows,
            columns: columns,
            mines: mines,
            emote: 'boom',
        });
        minesweeper.start();

        const matrix = minesweeper.start();
jozsefsallai commented 2 years ago

You mean this is always your output? Or just very similar to this?

The algorithm used for planting the mines is a very simple random number generator. So if you always get the same or similar results, it means either:

Try running this before the generation and show me the matrix it produces:

const matrix = new Array(7).fill(null).map(e => new Array(9).fill(0));

for (let i = 0; i < 30; i++) {
  const x = Math.floor(Math.random() * 7);
  const y = Math.floor(Math.random() * 9);

  if (matrix[x][y] === 1) {
    i--;
  } else {
    matrix[x][y] = 1;
  }
}
adan-ea commented 2 years ago

I'm having really similar results, every bomb on the top with way too many rows. I do have bad luck but this time i'm almost sure it's not it

Here : image image

jozsefsallai commented 2 years ago

The output seems normal to me here.

To be honest what weirds me out even more is that you asked for 7 rows and you somehow got 11 instead... I honestly haven't ever seen anything like this before.

Have you tried uninstalling and reinstalling the module? Also can you show me the full akairo command file? FYI I'm using akairo + discord.js-minesweeper too in my bot and it works fine, so I doubt that's the problem. Here's the code I have anyway: https://github.com/thimble-bot/thimble-bot/blob/master/src/commands/fun/minesweeper.ts

jozsefsallai commented 2 years ago

Oh, I think I just realized what you're doing wrong! You're calling minesweeper.start(); twice, so it tries to repopulate the matrix twice as well, which currently results in undefined behavior like this.

adan-ea commented 2 years ago

Ooh... right, i'm so sorry i opened an issue for this.. Sorry for the waste of time !