title: Game solving algorithm (Buttonia, lights-out variant)
body: <p>I am trying to create a solvability function for a game algorithm. Basically a function that returns true or false for a given game it if is solvable or not.</p>
  
  <p>The game is Buttonia.com (which does not implement the algorithm as yet), a type of lights-out game. Basically You have a grid of buttons, each of which, when pressed, will change the state of some of it's neighbors. Currently I generate a random game configuration and then apply heuristics as far as possible. The rest is decided by brute force search.</p>
  
  <p>My progress so far was to create a system of equations to model the game. As each button needs to change state an odd number of times to end up in a down state, It's equation would be this:</p>
  
  <p>button_A = 1 - (button_1 + button_2 + ... + button_X) % 2</p>
  
  <p>Where button_1 through button_X are the states of the buttons with an effect on button_A. Some buttons may be immediately resolved, if they are not dependent on others. For the rest, I try one configuration until I get a conflict and then back track.</p>
  
  <p>Currently this algorithm is practical for smaller configurations of games. I've tested it from 3x3 games up to sizes of 10x10. Where 6x6 is near an upper limit for practical play.</p>
  
  <p>The equations hugely cut down the search space from brute-force, making it practical. There might be a purely mathematical way of solving the system of equations.</p>
  
  <hr>
  
  <p>Sample 3x3 game in ascii (from <a href="http://buttonia.com/?game=2964" rel="nofollow noreferrer">buttonia.com/?game=2964</a>):</p>
  
  <pre><code>||#
  -o-
  +#|
  
  Legend:
  o = affect only self
  - = affect left and right neighbors
  | = affect above and below neighbors
  + = affect left, right, above and below neighbors
  # = affect all 8 surrounding neighbors
  </code></pre>
  
  <p>Solution, press these: (0,0), (2,0), (1, 2), (0, 1), (1, 1), (2,1)</p>
  
  <p>Equations for this game:</p>
  
  <pre><code>Button_0_0 = 1 - (0) % 2
  Button_1_0 = 1 - (Button_2_0) % 2
  Button_2_0 = 1 - (0) % 2
  Button_0_1 = 1 - (Button_0_0 + Button_0_2 + Button_1_2) % 2
  Button_1_1 = 1 - (Button_1_0 + Button_2_0 + Button_0_1 + Button_2_1 + Button_1_2) % 2
  Button_2_1 = 1 - (Button_2_0 + Button_1_2 + Button_2_2) % 2
  Button_0_2 = 1 - (Button_1_2) % 2
  Button_1_2 = 1 - (Button_0_2) % 2
  Button_2_2 = 1 - (Button_1_2) % 2
  </code></pre>
  
  <p>Potential solution:</p>
  
  <p>Changing the mathematical functions to avoid the need for the modulus lets us move the terms on the left side to the right, creating the neat matrix setup we need for the Gaussian method. So the first two equations would respectively convert to:</p>
  
  <pre><code>-1 = -1*B00 +  0*B10 +  0*B20 +  0*B01 +  0*B11 +  0*B21 +  0*B02 +  0*B12 +  0*B22
  -1 =  0*B00 + -1*B10 + -1*B20 +  0*B01 +  0*B11 +  0*B21 +  0*B02 +  0*B12 +  0*B22
  </code></pre>
  
  <p>Discussed solution here: <a href="https://stackoverflow.com/questions/1216176/gaussian-elimination-with-custom-operators">Gaussian Elimination with custom operators</a></p>
  
  <p>Getting closer. Almost ready to post full solution: <a href="https://stackoverflow.com/questions/1248216/inverting-binary-networks">Inverting binary networks</a></p>