for the life of me i cannot get Game of Life to run properly. I've coded it on darkbasic, I've been through the code many times. any help would be appreciated
it manually sets a gosper-glider-gun, there must be a problem with teh rules for the game because it just dissipates rather than produce gliders, and when i set it with random cells, there are no oscillators, it just sets into a permanent pattern
type golife
state
neighbors
sprite
endtype
dim c[40, 40] as golife
setvirtualresolution(600, 600)
handleMenu( )
function handleMenu( )
showLogo( )
REM LOAD Menu
REM PLAY Menu
level = 1
REM UNLOAD Menu
endfunction level
function showLogo( )
rem make sprites
for x = 0 to 39
for y = 0 to 39
c[x, y].sprite = createSprite( 0 )
setSpriteSize( c[x, y].sprite, 15.0, 15.0 )
setSpritePosition( c[x, y].sprite, x * 15.0, y * 15.0 )
next y
next x
rem set initial cells
c[1, 5].state = 1
c[1, 6].state = 1
c[2, 5].state = 1
c[2, 6].state = 1
c[11, 5].state = 1
c[11, 6].state = 1
c[11, 7].state = 1
c[12, 4].state = 1
c[12, 8].state = 1
c[13, 9].state = 1
c[13, 3].state = 1
c[14, 9].state = 1
c[14, 3].state = 1
c[15, 6].state = 1
c[16, 8].state = 1
c[16, 4].state = 1
c[17, 5].state = 1
c[17, 6].state = 1
c[17, 7].state = 1
c[18, 6].state = 1
c[21, 3].state = 1
c[21, 4].state = 1
c[21, 5].state = 1
c[22, 3].state = 1
c[22, 4].state = 1
c[22, 5].state = 1
c[23, 6].state = 1
c[23, 2].state = 1
c[25, 1].state = 1
c[25, 2].state = 1
c[25, 6].state = 1
c[25, 7].state = 1
c[35, 3].state = 1
c[35, 4].state = 1
c[36, 3].state = 1
c[36, 4].state = 1
rem Display Animated Logo
repeat
//do
updateCells( )
Sync( )
//loop
until done = 1
rem remove sprites
for x = 0 to 39
for y = 0 to 39
deleteSprite( c[x, y].sprite )
next y
next x
endfunction
function updateCells( )
REM Count neighbors
for x = 0 to 39
for y = 0 to 39
c[x, y].neighbors = 0
for u = x-1 to x+1
for v = y-1 to y+1
if u > -1 and u < 40 and v > -1 and v < 40 and u <> x and v <> y
if c[u, v].state = 1 then c[x, y].neighbors = c[x, y].neighbors + 1
endif
next v
next u
next y
next x
REM Update cells
for x = 0 to 39
for y = 0 to 39
if c[x, y].state = 0
rem if cell is dead
if c[x, y].neighbors = 3
c[x, y].state = 1
endif
else
rem if cell is alive
if c[x, y].neighbors = 2 or c[x, y].neighbors = 3
else
c[x, y].state = 0
endif
endif
next y
next x
REM Show cells
for x = 0 to 39
for y = 0 to 39
if c[x, y].state = 1
setSpriteColor( c[x, y].sprite, 255, 255, 255, 255 )
else
setSpriteColor( c[x, y].sprite, 255, 0, 0, 255 )
endif
next y
next x
endfunction