Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - the game of Life; problems with life detection
    primarykey
    data
    text
    <p>I'm attempting the <a href="http://www.bitstorm.org/gameoflife/" rel="nofollow">Game of Life</a> - what I'm stuck on is determining whether a space should be alive or dead based on the area around it. I'm at the point where I can't tell what I'm doing wrong - hopefully another set of eyes can help.</p> <p>This is just a snippet, full code here: <a href="http://pastebin.com/ucYe653p" rel="nofollow">http://pastebin.com/ucYe653p</a></p> <pre><code>public static void updateMatrix(boolean[][] board, int[] birthLive) { //clone the board so modified values don't affect the results of upcoming spaces boolean[][] boardCopy = board.clone(); for (int i = 0; i &lt; board.length; i++) boardCopy[i] = board[i].clone(); int count = 0; for (int i = 1; i &lt; board.length - 1; i++) { for (int j = 1; j &lt; board[i].length - 1; j++) { //different requirements for dead or living pieces' living status if (board[i][j] == false) { //check the nine-by-nine square, starting at (-1, 1) and ending at (1, -1) where 0 is the affected location // * * * // * 0 * // * * * for (int ii = board[i - 1].length; ii &lt; board[i + 1].length; ii++) { for (int jj = board[j - 1].length; ii &lt; board[j + 1].length; jj++) { if (boardCopy[i][j] == true) count++; } } //check to see what high and low amt of required adjacent lifeforms is if (count &gt;= birthLive[0] &amp;&amp; count &lt;= birthLive[1]) board[i][j] = true; else board[i][j] = false; count = 0; } else { for (int ii = board[i - 1].length; ii &lt; board[i + 1].length; ii++) { for (int jj = board[j - 1].length; ii &lt; board[j + 1].length; jj++) { if (boardCopy[i][j] == true) count++; } } count -= 1; //For board[i][j] is always true if (count &gt;= birthLive[2] &amp;&amp; count &lt;= birthLive[3]) board[i][j] = true; else board[i][j] = false; count = 0; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload