Hi all,
I'm coding Conway's Game of Life for my Java class and I've run into some logic errors.
My problem so far is the fact that I have a section of code that looks similar to this:
if(board[i][j+1].getLife() == 1)
board[i][j].setNumNeighbors(1); //Where setNumNeighbors(int n) { numNeighbors +=1}
}
etc, etc, so I have 8 different comparisons to check in 8 different directions to see if index [j] has a neighbor or not. Now, what I've noticed through testing is that numNeighbors either doesn't reset, and when it does reset, somehow plots with 0 neighbors are returning their neighbors to be 6, 8, 3, etc - which obviously is incorrect.
I have these statements in a Try/Catch as follows:
try{
/*comparison statements here*/
}catch(Exception e){
//ignore exception
}
So I assume what I'm doing with the Try/Catch is throwing the comparison statements out of the loop when it hits an ArrayOutOfBoundsException. Not being as familiar with exceptions as I should be, could someone please explain what I need to do with the exception statement? I thought if I ignored the exception with a blank line of code it would continue its comparisons of the 2D array without just throwing out the function and continuing on.
Thanks in advance for any help!