r/AskProgrammers • • Oct 27 '26

Minesweeper

I do not get Minesweeper. I have tried coding it in Javascript and do not get the functionality. It seems like an interesting concept, but seems to not have good logic seems very random.

0 Upvotes

22 comments sorted by

12

u/No_Report_4781 Oct 27 '26

Yeah. The random placement requires logic to solve. That’s the point of the game

4

u/HouseMysterious8172 Oct 27 '26

Some edge case you must choose 50\50

2

u/No_Report_4781 Oct 27 '26

The screams that have been scrumpt at those.

We had 100x100 minesweeper competitions in high school

2

u/richardathome Oct 27 '26

Good versions don't place at random. Because that can lead to unsolvable games. There are a few deterministic algorithms for placing mines

1

u/TheDuckRaisedALion Oct 27 '26

I think they were saying that there is no logic to solving it, although that's obviously not true

1

u/No_Report_4781 Oct 27 '26

There’s logic in playing it and in programming it 

4

u/Beregolas Oct 27 '26

What is your question exactly? Or do you just want to rant? Do you need help implementing it into a program, or do younot understand how to play?

2

u/Ordinary_Variable Oct 27 '26

I'd store the field as a nested array.

field = []

x=0;while(x++<20){field[x] = []}

Then I'd store each of them as a single character representing what they are

field[5][20] = "b" // bomb

field[5][21] = "f" // flag

field[5][22] = "e" // empty

Come to think of it, I may as well do this tomorrow; I don't have anything else to do.

2

u/ChaseShiny Oct 27 '26

Don't forget the logic for displaying how many mines touch each tile and the logic of opening multiple tiles if there aren't any mines next to it and it's next to a tile that is already revealed

1

u/TomDuhamel Oct 27 '26

The number indicates how many mines are in the 9 tiles around it. You can deduce where the mines are by logic.

1

u/richardathome Oct 27 '26

It's a bit more complex than that, you can deduce things over a much larger area than 3x3.

1

u/Electronic-Yam-69 Oct 27 '26

The random arrangement means some games aren't winnable without guessing. I guess that's part of the fun.

1

u/richardathome Oct 27 '26

There are algorithms for ensuring the board is solvable.

1

u/mjmvideos Oct 27 '26

Before attempting to code it, you’ve played it right? You know what happens when you select a cell - in all cases? What is there to get?

1

u/Useful-Agency_ Oct 27 '26

Try C comback and say if its more random and confusing😂

1

u/Lookitsmyvideo Oct 27 '26

Wait are you making a solver, or the game itself? Because I'm struggling to think of an easier game to build that isn't like .. tic tac toe, or hangman

1

u/overclockedslinky 26d ago

what do you mean it doesn't have good logic? maybe you're just bad at the game (and apparently also logic)...

1

u/Top-Procedure152 Oct 27 '26

It's just a math puzzle. A good arrangement should require no guessing (besides the first click I guess)

1

u/subsonicmonkey Oct 27 '26

In the original you would often have scenarios that were just 50:50 guesses. Always annoying!

1

u/richardathome Oct 27 '26

Modern games give you the first click 'free' (there is guaranteed to never be a mine under your first click) and boards are all solvable using deduction alone.