joker
journeyman
Reged: 07/19/06
Posts: 58
|
|
I was wondering if anyone is familiar with game of life algorithm. I am trying to implement if but have trouble checking neighboring cells. I am working with 2d array of size [10][10]. Every cell has 8 neighbours and I am suppose to check each of those 8 cells that surround cell that I am currently on. Anyone has any suggestion?
Thanks
|
hiwa
Carpal Tunnel
Reged: 06/21/03
Posts: 7704
Loc: Japan
|
|
Neighbors for the cell[x][y] would be (clock-wise from left-top) cell[x-1][y-1] cell[x][y-1] cell[x+1][y-1] cell[x+1][y] cell[x+1][y+1] cell[x][y+1] cell[x-1][y+1] cell[x-1][y]
Use double for-loops for iterating on them.
If the edge cells are wrapped around to the cells on the other side of edge, the neighbor computation should be sligtly different for them.
-------------------- *stop cruelty* Annual number of euthanized cats&dogs: US 5M, JP 500K.*for our better karma*
|
joker
journeyman
Reged: 07/19/06
Posts: 58
|
|
Yeah thanks so much for reply. The cells wrap around but I implemented somehow before I got your post. It took me a while to figure out how it works but I did it. I really appreciate the reply. Thank you
|