P
Paul Morrison
My implementation of the Game of Life stores the cells in the type: byte[][]
The sides of the world must *wrap* around, ie a cell on the very right of
the world is actually the neighbour of the cell on the very left of the
world.
When wanting to insert a glider into the word the following code is used:
public void glider (int i, int j) throws NotInLifeException {
cell[j] = Cell.ALIVE;
cell[j+2] = Cell.ALIVE;
cell[i+1][j+1] = Cell.ALIVE;
cell[i+1][j+2] = Cell.ALIVE;
cell[i+2][j+1] = Cell.ALIVE;
}
ie:
...X .X..
.....XX..
.....X.....
The problem is when the glider gets to the edge of the world. In order to
check that the glider will stay in the world I have used the following code:
public void checkBounds (int i, int j) {
while (i < 0) {
i += width;
}
while (i > width) {
i -= width;
}
while (j < 0) {
j += depth;
}
while (j > depth) {
j -= depth;
}
}
The problem I am having is incorporating the checkBounds method into the
glider method. Any help would be appreciated.
Paul Morrison
The sides of the world must *wrap* around, ie a cell on the very right of
the world is actually the neighbour of the cell on the very left of the
world.
When wanting to insert a glider into the word the following code is used:
public void glider (int i, int j) throws NotInLifeException {
cell[j] = Cell.ALIVE;
cell[j+2] = Cell.ALIVE;
cell[i+1][j+1] = Cell.ALIVE;
cell[i+1][j+2] = Cell.ALIVE;
cell[i+2][j+1] = Cell.ALIVE;
}
ie:
...X .X..
.....XX..
.....X.....
The problem is when the glider gets to the edge of the world. In order to
check that the glider will stay in the world I have used the following code:
public void checkBounds (int i, int j) {
while (i < 0) {
i += width;
}
while (i > width) {
i -= width;
}
while (j < 0) {
j += depth;
}
while (j > depth) {
j -= depth;
}
}
The problem I am having is incorporating the checkBounds method into the
glider method. Any help would be appreciated.
Paul Morrison