13

I have implemented in Python an algorithm for solving the game 'Minesweeper'. The program works as follows:

Say that the solver clicks a square named 'a'. For sake of example let the number thus revealed equal 2. The neighbours of the square which are as yet unclicked are (again by way of example) named 'b' and 'c'. The program then associates the square with the expression [2, {'b', 'c'}], and strips 'a' from all other expressions. The deduction of which squares are mines and which are not proceeds by pairwise simplification of such expressions under two circumstances.

  • If the squares in one expression are a subset of the squares of the other expression:

    [2, {'a', 'b', 'c'}], [1, {'a', 'b'}] -> [1, {'c'}], [1, {'a', 'b'}]
    
  • If all the squares in one expression are established to be mines:

    [2, {'a', 'b'}], [1, {'b', 'c'}] -> [2, {'a', 'b'}], [0, {'c'}]
    

Then, for some expression X, if X[0] == 0, we are free to click all squares named in X[1], and if X[0] == len(X[1]), then we can flag them.

I am, however, struggling to identify which pairs of expressions to attempt to simplify. My current approach is to maintain a stack of squares; whenever a square is clicked, or has its expression successfully simplified, it is added to the stack (if it is not already there). When a square is popped from the stack, simplification is attempted between its expression (X), and any other expressions Y such that X[1] & Y[1] != set(). The algorithm terminates when the stack is depleted. Currently however, though this works quite well, it is not capable of correctly solving all unambiguous configurations, and how well it performs on a given board changes significantly if I replace the stack with a queue, or use some algorithm to determine which square to pop!

I would be very much appreciative for any examples of precedent to my approach, or avenues of potential exploration.

4

2 に答える 2

0

これが頭に浮かんだのですが、あなたの方法が正確に何であるかを完全に視覚化することはできませんでした.
グラフィカルな形式で私のものを提示することが、その労力を節約するのに役立つことを願っています.

画像は「読み順」で進みます。

これは、未知のタイルに与えられた値に、その一時値を取得している既知のタイルの数を追加すると、リスクを正しくモデル化する可​​能性がさらに高まる可能性があるという、これを投稿してから行った作業と一致しているようです。
(これを使用すると、16 (または最初の方法では 8) の temp 値が重要です。これは、地雷が単独で達成できる最大の数値であるためです)


これをもっと早く見ないと少し盲目な気がします。

100% に正規化される値を持つものはすべて、私が見つけることができるすべてのケースで、地雷です。

于 2012-10-29T04:04:39.470 に答える