## Conway's Game of Life in Commodore BASIC

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
monsonite
Posts: 76
Joined: 17 May 2018, 07:17

### Conway's Game of Life in Commodore BASIC

As some will know John H Conway - who devised the game "Life" passed away on April 11th.

As a tribute, some of our friends on the retrocomputing forum have recreated a version of Life in Commodore BASIC.

https://retrocomputingforum.com/t/conwa ... basic/1153

I'm going to have a go at getting this running on the Gigatron

Code: Select all

``````10 BB=0 : REM CONFIG, 1=BEEB, 0=COMMODORE
20 IF BB=0 THEN PRINTCHR\$(147);CHR\$(18);:GOTO 30
25 MODE 7
30 PRINT"  CONWAY'S GAME OF LIFE  "
40 PRINT:PRINT"IN MEMORIAM JOHN H CONWAY"
50 PRINT"26 DEC 1937 - 11 APR 2020":PRINT
60 INPUT"WIDTH, HEIGHT (EG, 8,8)";W,H
70 IF W<4 THEN W=4
80 IF W>39 THEN W=39
90 IF H<4 THEN H=4
100 IF H>24 THEN H=24
110 G=0:A=0:P=0:W=W+1:H=H+1:D1=W+1:D2=W-1:K=0:NG=1:XM=W-1:YM=W*H-W:N=0
120 IF BB=0 THEN 140
130 CS=12:CH=30:CO=79-32:R=1:GOTO150
140 CS=147:CH=19:CO=209-32:R=0
150 PRINT:PRINT"PROBABILITY OF INITIAL POPULATION:":INPUT"(0>P<1)";P
160 IF P<=0 OR P>=1 THEN P=0.5
170 DIM M%(1,W*H+W):PRINTCHR\$(CS);
180 FORY=W TOYM STEPW:FORX=1TOXM:M%(0,Y+X)=RND(R)<P:NEXT:NEXT
190 PRINTCHR\$(CH);"GEN.:";N
200 FORY=W TOYM STEPW:FORX=1TOXM:PRINTCHR\$(32-M%(G,Y+X)*CO);:NEXT:PRINT:NEXT
210 FORY=W TOYM STEPW:FORX=1TOXM:A=Y+X
220 K=M%(G,A-D1)+M%(G,A-W)+M%(G,A-D2)+M%(G,A-1)+M%(G,A+1)
230 K=K+M%(G,A+D2)+M%(G,A+W)+M%(G,A+D1):M%(NG,A)=(K=-3)OR(K=-2 ANDM%(G,A)=-1)
240 NEXT:NEXT:G=NG:NG=1-G:N=N+1:GOTO190``````

marcelk
Posts: 490
Joined: 13 May 2018, 08:26

### Re: Conway's Game of Life in Commodore BASIC

Keep in mind that if you want to save into, and type back from, BabelFish, then use a recent version. By looking at the line ending it determines if you've saved from MS BASIC. If so, BabelFish slows down the type back speed so that MS BASIC can keep up while it's tokenising the lines.

The 511 bytes available Pluggy McPlugface aren't enough. It may not even fit immediately in 1023 bytes, because it stores CR + LF. Some squeezing is needed. Then it should work.