'so called Game of Life, though not a real game.
'Based on mathematician, John H. Conway's 1970 simulation that he called
'the Game of Life. There is no winning or losing, just experimenting.
'Cells are kept alive with 2-3 living cells around them
'Cells are brought to life if there are 3 live cells around
'Cells Die of loneliness if there are 1-0 live cells around
'Cells are smoothered if there are 4 or more live cells around.
CONST MaxX
= 50 'number of columns 127 max CONST SX
= 500 'size of board in pixels X, 510 max(cause instruction area) CONST MaxY
= 30 'number of rows 127 max CONST SY
= 470 'size of board in pixels Y,480 max(screen size limitation) CONST Pass
= 85 'random chance of life 0-100%(0=All live, 100=all dead, I know its backwards)
ClearBoard Board()
MakeRandom Board()
Speed! = .25
'--------------------INPUT-------------------------
ExitFlag%% = TRUE
CASE "A" 'Turn on Automatic cycle Auto = TRUE
CASE "S" 'Step 1 turn/Turn off Automatic cycle AgeBoard
CASE "C" 'Clear Board/Turn off Automatic Cycle ClearBoard Board()
CASE "F" 'random Fill board grid/Turn off Automatic Cycle MakeRandom Board()
Speed! = Speed! + .05
IF Speed!
>= 1.5 THEN Speed!
= 1.5 Speed! = Speed! - .05
IF Speed!
<= .05 THEN Speed!
= .05 '-------------------------------------------------------
'----------------------MOUSE----------------------------
'-------------------------------------------------------
'--------------------Display----------------------------
DrawGrid MaxX, MaxY
DrawCells Board()
'-------------------------------------------------------
Live%% = Check_Live(x%%, y%%) 'how many cells around the current one are alive?
IF Live%%
= 3 AND (NOT Board
(x%%
, y%%
)) THEN GiveLife x%%
, y%%
'just right for NEW life! IF Live%%
<= 1 AND Board
(x%%
, y%%
) THEN TakeLife x%%
, y%%
'not enough friends IF Live%%
>= 4 AND Board
(x%%
, y%%
) THEN TakeLife x%%
, y%%
'TOO many friends
B(x%%, y%%) = FALSE
ToggleCell
= NOT B
(X%%
, Y%%
)
Result%% = 0
StartX%% = 0: StartY%% = 0
EndX%% = 0: EndY%% = 0
'check that current cells neighbors are within the grid array
FOR Ix%%
= StartX%%
TO EndX%%
FOR Iy%%
= StartY%%
TO EndY%%
'dont bother with current cell being checked so dont process it
'return the number of live cells around current cell
Check_Live = Result%%
Board(X%%, Y%%) = ToggleCell(X%%, Y%%, Board())
Board(X%%, Y%%) = ToggleCell(X%%, Y%%, Board())
ScaleY = SY \ MaxY
ScaleX = SX \ MaxX
LINE (0, 0)-(SX
, SY
), White
, B
LINE (Ix%
, 0)-(Ix%
, SY
), White
LINE (0, Iy%
)-(SX
, Iy%
), White
ScaleY = SY \ MaxY
ScaleX = SX \ MaxX
IF B
(X%%
, Y%%
) THEN LINE (1 + X%%
* ScaleX
, 1 + Y%%
* ScaleY
)-STEP(ScaleX
- 1, ScaleY
- 1), Blue
, BF
ELSE LINE (1 + X%%
* ScaleX
, 1 + Y%%
* ScaleY
)-STEP(ScaleX
- 2, ScaleY
- 2), Black
, BF
ScaleY = SY \ MaxY
ScaleX = SX \ MaxX
MX%% = X% \ ScaleX
MY%% = Y% \ ScaleY
B(MX%%, MY%%) = ToggleCell(MX%%, MY%%, B())