So. I have a problem I simply cant get my head around. I'm currently making a cellular automaton. (Java) For this, I have 2 Arrays, one called cells[][] for current states, and one called cellsX[][] for the temporary state inbetween steps.
at each update i do this:
public void updateCells() {
cellsX = cells;
for(int i = 0; i< Xsize; i++) {
for(int j = 0; j < Ysize; j++) {
cellsX[i][j].Update();
}
}
}
And later I render:
for(int i = 0; i< Xsize; i++) {
for(int j = 0; j < Ysize; j++) {
if(cells[i][j].isAlive()) {
int Colori[] = cells[i][j].GetColor();
g2d.setTransform(identity);
g2d.translate(0, 0);
g2d.setColor(new Color(Colori[0],Colori[1],Colori[2]));
g2d.drawRect((i*5)+20, (j*5)+20, 5, 5);
}
}
}
Right now, I would say nothing should happen, as I newer update cells[][] but for some reason it do? How can the cells[i][j] update, when the only cell I've given a command is cellsX[i][j]?
to show you the Update function in the Cell
public void Update() {
if(Info[0][0] > 0) {
Info[0][0] += 1;
Info[0][2] += rand.nextInt(2);
}
Info[1][0] ++;
if(Info[1][0] >255) Info[1][0] =0;
if(Info[0][0] > Info[0][1]) Info[0][0] = 0;
if(Info[0][2] <= 0) Info[0][0] = 0;
}
Its a void an no nothing to affect the outside world (Info[][] is an int array used to store data such as life and color (Info[1][0] is the red color)
I have no idea how the H. i can mess up. the creation of the cells and cellsX is
int Xsize = 100;
int Ysize = 100;
Cell[][] cells = new Cell[Xsize][Ysize];
Cell[][] cellsX = new Cell[Xsize][Ysize];
and initialized:
for(int i = 0; i< Xsize; i++) {
for(int j = 0; j < Ysize; j++) {
cellsX[i][j] = new Cell();
}
}
for(int i = 0; i< Xsize; i++) {
for(int j = 0; j < Ysize; j++) {
cells[i][j] = new Cell();
}
}
Sorry for the wall of text... I just can't figure out how cells get's updated :S