Generate a minesweeper board which doesn't nee

2020-05-19 02:16发布

问题:

I am designing a Minesweeper-like game (with modified rules), and I want to prevent player from guessing. My goal is: The generated board is with few revealed squares, and player can solve the entire puzzle without any guessing.

Wikipedia mentioned:

Some implementations of Minesweeper will set up the board by never placing a mine on the first square revealed, or by arranging the board so that the solution does not require guessing.

However, I cannot figure out the algorithm.

Besides, in another StackOverflow question: Minesweeper solving algorithm

Improvement: Run the solver alongside the generator, making sure that the puzzle has a unique solution. This takes some cleverness, and isn't done in most variants.

I doubt if this really works. It's well-known solving minesweeper is NP-complete.

In summary, my questions are:

  • How to generate a Minesweeper board which doesn't need any guessing?
  • If we can, what's the concrete algorithm?
  • Could we solve this problem in polynomial time deterministically? Is this problem NP-complete? How to prove it?

回答1:

The implementation of Minesweeper in Simon Tatham's Portable Puzzle Collection is guessing-free. (It's also MIT licensed, so you're free to copy his implementation if you so desire.)



回答2:

It's well-known solving minesweeper is NP-complete.

This is true but perhaps not as relevant as you think. The proposed algorithm is something like "repeatedly generate random boards until the computer can solve one". NP-hardness is a property of the worst case, but here we're really interested in the average-case hardness. If an unusually hard board is generated, we can time out the solver and restart with a new board.

Also, even if there were an oracle to distinguish good boards from bad, would you really want the user to have to solve a hard problem in order to avoid guessing? A less talented computer solver might bias the choice toward fairer boards.