If you don't, google for it : it's a famous mathematical simulation (invented by Conway) displaying the life of arbitrary groups of tokens (called cells) on a checkerboard, given two simple rules telling that :
1/ a living cell survives to the next generation if it has 2 or 3 neighbours, no less nor more.
2/ a new cell is born in an empty square if it is surrounded by exactly three living cells.
I found a (short) SuperBasic program of this simulation, that I wrote a long time ago. My program considers a checkerboard (a "world") that although finite does not have boundaries, because it is "warped" in both directions x and y (like a torus).
Normally, a game of life may be displayed in black and white, but my program uses the three colors available in MODE 4, to display the cells just born in GREEN, the cells surviving in WHITE and the cells that just have died in RED.
You can see that the main (longest) procedure of this program is called LIFE, which does REPeat a loop called GENERATION.
Inside this loop GENERATION, you can see two tasks, the first called DAD and the second MOM.
DAD will evaluate for each square of the checkerboard how many cells are surrounding it ; and then MOM, depending on these results, will enforce the two rules to let cells be born or survive.
If you were doing this looking systematically at every square, the execution time would be proportionnal to the total size (number of squares) of the "world". Instead, my design uses two stacks that let DAD and MOM tell each other the often much fewer squares that are to be examined. The execution time is thus not proportionnal to the size of the world but to the number of squares hosting living cells (and neighbours). So, beside the main procedure there are 4 functions to manage these stacks.
Then, there are also three procedures ( BIG SMALL TINY ) to decide of the size of the squares (and inversely, the size of the world)
And an initialisation procedure PLAGUE that clears the whole world of any living cell.
You may populate the world cell by cell calling the procedure CELL, but you may also add procedures creating - with the help of a generic scanning procedure called SYMBIOSIS - complex living organisms, taking for examples GLIDER or BOMBER .
Calling GLIDER for instance, you will observe a little organism that moves diagonally over the "world". On a basic QL even this simple model is rather slow. On an emulator at full speed, it is more interesting, and you may even dare to run the BOMBER : this one is an organism that periodically shoots a GLIDER... but finally gets eaten by them because of the warped world.
The SuperBasic code :
Code: Select all
REM Conway's game of Life: version SuperBASIC
REM Copyright Paul KOPFF, Clamart (France)
WINDOW#1,480,256,20,0
MODE 4 : PAPER#1,0 : CLS
a = RESPR(40960)
1100 DEFine PROCedure PUSH1( n )
1110 POKE_W sp1,n
1120 sp1 = sp1 + 2
1130 END DEFine PUSH1
1140 DEFine FuNction POP1
1150 sp1 = sp1 - 2
1160 IF sp1 = sp1u THEN
1170 sp1 = sp1f
1180 RETurn -1
1190 END IF
1200 RETurn PEEK_W(sp1)
1210 END DEFine POP1
1220 DEFine PROCedure PUSH2( n )
1230 POKE_W sp2,n
1240 sp2 = sp2 - 2
1250 END DEFine PUSH2
1260 DEFine FuNction POP2
1270 sp2 = sp2 + 2
1280 IF sp2 = sp2u THEN
1290 sp2 = sp2f
1300 RETurn -1
1310 END IF
1320 RETurn PEEK_W(sp2)
1330 END DEFine POP2
1340 DEFine PROCedure DOT( x,y,c )
1350 BLOCK lc , hc , x * lm , y * hm , c
1360 END DEFine DOT
1370 DEFine PROCedure BIG
1380 le = 48
1390 he = 32
1400 lm = 10
1410 hm = 8
1420 lc = 8
1430 hc = 6
1440 END DEFine BIG
1450 DEFine PROCedure SMALL
1460 le = 96
1470 he = 64
1480 lm = 5
1490 hm = 4
1500 lc = 4
1510 hc = 3
1520 END DEFine SMALL
1530 DEFine PROCedure TINY
1540 le = 160
1550 he = 128
1560 lm = 3
1570 hm = 2
1580 lc = 2
1590 hc = 1
1600 END DEFine TINY
1610 DEFine PROCedure LIFE
1620 REPeat GENERATION
1630 BEEP 2000,10
1640 REPeat DAD
1650 c = POP2
1660 IF c = -1 THEN EXIT DAD
1670 m = PEEK(c+a)
1680 IF m > 31 THEN
1690 x = c MOD le
1700 y = c DIV le
1710 FOR i = -1 TO 1
1720 xv = ( x + i ) MOD le
1750 FOR j = -1 TO 1
1760 yv = ( y + j ) MOD he
1790 cv = xv + le * yv
1800 mv = PEEK(cv+a)
1810 nv = mv MOD 16
1820 IF nv = 0 THEN PUSH1 cv
1830 POKE cv+a,mv+1
1840 END FOR j
1850 END FOR i
1860 ELSE
1870 IF m > 15 THEN PUSH1 c
1880 END IF
1890 END REPeat DAD
1900 REPeat MOM
1910 c = POP1
1920 IF c = -1 THEN EXIT MOM
1930 m = PEEK(c+a)
1940 x = c MOD le
1950 y = c DIV le
1960 n = m MOD 16
1970 IF m > 31 THEN
1980 IF n = 3 OR n = 4 THEN
1990 IF m > 48 THEN DOT x,y,7
2000 PUSH2 c
2010 POKE c+a,32
2020 ELSE
2030 IF m <> 48 THEN
2040 DOT x,y,2
2050 PUSH2 c
2060 POKE c+a,16
2070 END IF
2080 END IF
2090 ELSE
2100 IF n = 3 THEN
2110 DOT x,y,4
2120 PUSH2 c
2130 POKE c+a,48
2140 ELSE
2150 IF m > 15 THEN DOT x,y,0
2160 POKE c+a,0
2170 END IF
2180 END IF
2190 END REPeat MOM
2200 END REPeat GENERATION
2210 END DEFine LIFE
2220 DEFine PROCedure PLAGUE
2230 CLS
2240 FOR i = a TO a + he * le
2250 POKE i , 0
2260 END FOR i
2270 sp1u = a + 20478
2280 sp1f = a + 20480
2290 sp2u = a + 40960
2300 sp2f = a + 40958
2310 sp1 = sp1f
2320 sp2 = sp2f
2330 END DEFine PLAGUE
2340 DEFine PROCedure CELL( x,y )
2350 x = x MOD le
2360 y = y MOD he
2370 c = x + le * y
2380 POKE c+a,48
2390 PUSH2 c
2400 DOT x,y,4
2410 END DEFine CELL
2630 DEF PROCedure SYMBIOSIS( xv,yv )
2640 READ n
2650 FOR i = 1 TO n
2660 READ x
2670 READ y
2710 CELL x+xv,y+yv
2720 END FOR i
2730 END DEFine SYMBIOSIS
2420 DEFine PROCedure GLIDER
2430 DATA 5,0,0,1,0,2,0,2,1,1,2
2440 RESTORE 2430
2450 SMALL : PLAGUE
2460 SYMBIOSIS 10,10
2470 LIFE
2480 END DEFine GLIDER
2490 DEFine PROCedure BOMBER
2500 DATA 65,0,18,0,19,0,20,1,18,2,11,2,12,2,19,3,10,3,12
2510 DATA 4,12,8,17,8,18,9,8,9,9,9,10,9,16,9,17,10,10,10,18
2520 DATA 11,9,14,7,14,8,15,8,15,9,16,7,20,6,20,7,20,8,21,8
2530 DATA 22,7,22,19,22,20,23,10,23,11,23,12,23,18,23,19
2540 DATA 24,12,24,20,25,11,28,-1,28,0,28,9,28,10,29,-2,29,0
2550 DATA 29,10,29,11,30,0,30,9,34,20,34,21,34,22,35,20
2560 DATA 36,13,36,14,36,21,37,12,37,14,38,14,39,3,39,4
2570 DATA 39,5,40,5,41,4
2580 RESTORE 2500
2590 SMALL : PLAGUE
2600 SYMBIOSIS 6,6
2610 LIFE
2620 END DEFine BOMBER
glider

BYE Paul