I've been trying different algorithms, and just yesterday I adapted one from the Graphics Programmer's Black Book (the chapter 17), and it works... but doesn't wrap around the edges like the other algorithms do. It does vertically, but not horizontally. I'm doing the wrapping by using an extra outer border of cells all around, that each gets a copy of the opposite inner border.
I've been trying for hours to figure out why it isn't wrapping around but I got nowhere so far. Meanwhile I also burned out.
If someone else could take a look and see if they could figure out what's wrong, I'd appreciate it a lot. A fresh pair of eyes might see better than mine. I don't know if I should paste the code right here, as it's a little long (some 200 lines), so meanwhile it's in this repo right here. It's a simple console app, works on the windows console (don't know about the linux terminal).
There's two generation algorithms there for comparison, and you can easily switch using the algo variable. The SUM works fine, the BITS is the one that doesn't. Not sure what else to say. I tried commenting the code for clarity.
Well, if someone has 5 minutes to spare, I'll greatly appreciate it. Thanks in advance.
----------
EDIT: A specific symptom that I noticed (that I didn't think to mention earlier) is that when using the BITS algorithm (which uses bit manipulation, hence the name of the flag), the cells on the outter edges don't seem to be affected by this part of the code that kills a cell or the equivalent part to revive a cell (specifically the "[i-1]" and "[i+1]" lines, which should affect the cells to the sides of the cell being considered):
# if it's alive
if cellmaps[prev][j][i] & 0x01:
# kill it if it doesn't have 2 or 3 neighbors
if (n != 2) and (n != 3):
cellmaps[curr][j][i] &= ~0x01
alive_cells -= 1
# inform neighbors this cell is dead
cellmaps[curr][ j-1 ][ i-1 ] -= 2
cellmaps[curr][ j-1 ][ i ] -= 2
cellmaps[curr][ j-1 ][ i+1 ] -= 2
cellmaps[curr][ j ][ i-1 ] -= 2
cellmaps[curr][ j ][ i+1 ] -= 2
cellmaps[curr][ j+1 ][ i-1 ] -= 2
cellmaps[curr][ j+1 ][ i ] -= 2
cellmaps[curr][ j+1 ][ i+1 ] -= 2
The actual effect is that the leftmost and rightmost edges are always clear (actually, as depicted, the ones on the opposite side to where the actual glider is, are affected, but not the ones next to the glider).
when a glider approaches the edge, for exampple,
this edge should have 1 cell And the opposite side should
v like this not be like this, but this
V v V V
| . . . . | . . . . . . . .| . . . .|
| . . # . | . . # . . . . .| . . . .|
| . # . . | # # . . . . . #| . . # #|
| . # # . | . # # . . . . #| . . . #|
| . . . . | . . . . . . . .| . . . .|
| . . . . | . . . . . . . .| . . . .|