title: Game of life rules not working properly
body: <p>I have the following logic code for my Game of Life application in Java. I have the problem that the rules do not act like the default Conway's Game of Life rules. I have read up on them on <a href="http://en.wikipedia.org/wiki/Conway&#39;s_Game_of_Life#Rules" rel="nofollow noreferrer">Wikipedia</a>, and they are the following;</p>
  
  <ul>
  <li>Any live cell with fewer than two live neighbours dies, as if caused by under-population.</li>
  <li>Any live cell with two or three live neighbours lives on to the next generation.</li>
  <li>Any live cell with more than three live neighbours dies, as if by overcrowding.</li>
  <li>Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.</li>
  </ul>
  
  <p>I have attempted to duplicate these rules in the following code, but it acts unlike the normal Conway' Game of Life;</p>
  
  <pre><code>int surroundingLife = 0;
  if (lifeMap[cX+1][cY]) { //Right
      surroundingLife++;
  }
  if (lifeMap[cX-1][cY]) { // Left
      surroundingLife++;
  }
  if (lifeMap[cX][cY+1]) { // Above
      surroundingLife++;
  }
  if (lifeMap[cX][cY-1]) { // Below
      surroundingLife++;
  }
  if (lifeMap[cX-1][cY-1]) { // Bottom left
      surroundingLife++;
  }
  if (lifeMap[cX+1][cY+1]) { // Top Right
      surroundingLife++;
  }
  if (lifeMap[cX-1][cY+1]) { // Some other corner (I don't know which one)
      surroundingLife++;
  }
  if (lifeMap[cX+1][cY-1]) { // Yet another corner (I don't know which one)
      surroundingLife++;
  }
  if (running) {
      // Logic for life
      if (surroundingLife &lt; 2 &amp;&amp; lifeMap[cX][cY]) {// Rule 1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.
          lifeMap[cX][cY] = false;
      } else if (surroundingLife == 2 &amp;&amp; lifeMap[cX][cY]) { // Rule 2. Any live cell with two or three live neighbours lives on to the next generation.
          lifeMap[cX][cY] = true;
      } else if (surroundingLife == 3 &amp;&amp; lifeMap[cX][cY]) { // Rule 3. Same as above
          lifeMap[cX][cY] = true;
      } else if (surroundingLife &gt; 3 &amp;&amp; lifeMap[cX][cY]) { // Rule 4. Any live cell with more than three live neighbours dies, as if by overcrowding.
          lifeMap[cX][cY] = false;
      } else if (surroundingLife == 3 &amp;&amp; !lifeMap[cX][cY]) { // Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
          lifeMap[cX][cY] = true;
      }
  }   
  </code></pre>
  
  <p>This is how it looks after running a couple of generations;</p>
  
  <p><img src="https://i.stack.imgur.com/02IwQ.png" alt="GameOfBugs, or BugsOfLife."></p>
  
  <p>It reminds me of the 'maze' ruleset, which is odd.</p>
  
  <p>I don't believe there is a fault with my surroundingLife calculator, as it returns 8 when entities have 8 others surrounding them. Is the problem due to me looping through Y then X?</p>