Search code examples
algorithmminesweeper

Minesweeper algorithm


I am about to design my own minesweeper in Java. And while analyzing the real windows 7 minesweeper, I came across this situation.

1 or 0 ?

The uncovered square(pointed by arrow), may be 1 or mayn't have any number(an empty square). But in windows 7 minesweeper, this square has 1.

hypothesis: And by analyzing I came to know that all the mines are always surrounded by numbers.

If I go with my hypothesis, then no other go, the uncovered square should be 1.

And designing the logic for the minesweeper will be easier, if I follow this hypothesis. since,

step 1: Randomly assign the squares with mines.(Make the specific (i,j)element in the 2D array to be -1).

step 2: Number each square, equal to the number of mines surrounding it. (In this case, the hypothesis became true).

And my questions are,

  1. What wrong if the uncovered square is an empty square?
  2. Does that hypothesis is the rule in minesweeper?
  3. Does I have to follow the hypothesis, to make my coding simpler to implement?
  4. *If I proposed a new minesweeper with the rule against the hypothesis, does my new minesweeper will end up in instability?Is so,how?

*->I am not intentionally breaking the rules, I try to removing redundant hint/keys to the user.


Solution

  • Of course the pointed square has a number - it is adjacent to (exactly one) mine square so it gets a 1. The empty squares are just shorhand for zero.