title: Improving my Minesweeper solving algorithm
body: <p>I have implemented in Python an algorithm for solving the game 'Minesweeper'. The program works as follows:</p>
  
  <p>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.</p>
  
  <ul>
  <li><p>If the squares in one expression are a subset of the squares of the other expression:</p>
  
  <pre><code>[2, {'a', 'b', 'c'}], [1, {'a', 'b'}] -&gt; [1, {'c'}], [1, {'a', 'b'}]
  </code></pre></li>
  <li><p>If all the squares in one expression are established to be mines:</p>
  
  <pre><code>[2, {'a', 'b'}], [1, {'b', 'c'}] -&gt; [2, {'a', 'b'}], [0, {'c'}]
  </code></pre></li>
  </ul>
  
  <p>Then, for some expression <code>X</code>, if <code>X[0] == 0</code>, we are free to click all squares named in <code>X[1]</code>, and if <code>X[0] == len(X[1])</code>, then we can flag them. </p>
  
  <p>I am, however, struggling to identify <em>which</em> 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 (<code>X</code>), and any other expressions <code>Y</code> such that <code>X[1] &amp; Y[1] != set()</code>. 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!</p>
  
  <p>I would be very much appreciative for any examples of precedent to my approach, or avenues of potential exploration.</p>