private int[][] gameBoard;
private int[][] scratchBoard;
public Intboard(int[][] world)
{
gameBoard = world;
scratchBoard = world;
}
public void updateBoard()
{
gameBoard = scratchBoard;
}
//...skipping a bunch of confirmed working methods...
public void advanceOneGen()
{
for(int x = 1; x<gameBoard.length-1; x++)
{
for(int y = 1; y<gameBoard.length-1; y++)
{
if(gameBoard[x][y]!=2)
{
if(valueOfNeighbors(x,y)<=1 || valueOfNeighbors(x,y)>=4)
{
scratchBoard[x][y]=0;
}
if(valueOfNeighbors(x,y)==3 && gameBoard[x][y]==0)
{
scratchBoard[x][y]=1;
}
}
}
updateBoard();
}
}
My suspicion is that after the initializer, gameBoard[][], scratchBoard[][], and the (destroyed?) world[][] are all pointing to the same object. i'm thinking this because it seems to fit the problem (if advanceOneGen() was both reading from and modifying only one Board), but i could have sworn ints were immutable (and so a 2D array of them also should be, right?).
In case it might be relevant, this is for a Game of Life. the inital input is a cross, which i would expect to transform into a 3x3 box with an open center, but instead what's pictured.
here is a picture to be more clear:
http://img519.imageshack.us/img519/1150/38718066ff5.jpg