CONWAYS GAME OF LIFE
Posted: Sun Jun 11, 2023 12:07 am
I didn't plan on posting this until it was Done.
But I have some really weird bugs.. Sometimes it works
and sometimes it seems to work but the Graphics don't display.
I'm loath to point to a Bug in the Emulator or the Underlying BASIC code.
but it seems to be pointing in that direction..
There is no "Game of Life Code" yet besides setting up the variables. I first ran into this
Bug when I set up the code to choose the Grid Size. It sometimes runs correctly
and other times runs without doing any Graphics Output ...
I made two changes before this behaviour started. First I made the GRID dimensions
an INT GX%, GY%......... This was for memory usage. When they were the
default float I got an out of Memory Error on the more dense grid sizes (Multi dimensional array)
But I also wrote the Grid Selection Code before I ever posted anything into the Emulator.
This is the code..
But I have some really weird bugs.. Sometimes it works
and sometimes it seems to work but the Graphics don't display.
I'm loath to point to a Bug in the Emulator or the Underlying BASIC code.
but it seems to be pointing in that direction..
There is no "Game of Life Code" yet besides setting up the variables. I first ran into this
Bug when I set up the code to choose the Grid Size. It sometimes runs correctly
and other times runs without doing any Graphics Output ...
I made two changes before this behaviour started. First I made the GRID dimensions
an INT GX%, GY%......... This was for memory usage. When they were the
default float I got an out of Memory Error on the more dense grid sizes (Multi dimensional array)
But I also wrote the Grid Selection Code before I ever posted anything into the Emulator.
This is the code..
Code: Select all
10 SCREEN $80
80 GOSUB 700
90 P1=1:P2=2
100 C1=$05:C2 = $10
110 X = RND(-TI)
130 DIM GC%(2,GX,GY)
140 GOSUB 200 : REM INITGRID
150 GOSUB 300
155 GOSUB 400
160 GOTO 8000
REM INITGRID
200 CLS:COLOR 5:LOCATE 2,2:PRINT "INITIALIZING"
205 FOR X = 1 TO GX
210 FOR Y = 1 TO GY
215 LOCATE 3,3:PRINT "X:";X,"Y:";Y
220 GC%(P1,X,Y)= 0
230 J = INT(RND(1)*10)
240 IF J < 2 THEN GC%(P1,X,Y)= 1
250 NEXT Y
260 NEXT X
265 LOCATE 3,3:PRINT " ";
270 RETURN
299 REM DRAWGRID
300 LOCATE 2,2:PRINT "DRAWING THE GRID "
305 FOR Y = 1 TO GY
310 FOR X = 1 TO GX
320 IF GC%(P1,X,Y) = 1 THEN CC = C1
330 IF GC%(P1,X,Y) = 0 THEN CC = C2
340 X1 = (X*XS)-XS:Y1=(Y*YS)-XS
350 RECT X1,Y1,X1+XS-1,Y1+YS-1,CC
360 NEXT X
370 NEXT Y
380 RETURN
400 LOCATE 2,2:PRINT "UPDATING CELLS "
410 FOR Y = 1 TO GY
420 FOR X = 1 TO GX
430 T = 0: REM CELL SCORE TALLY
440 REM CODE TO TALL CELL SCORE HERE.
500 NEXT X
510 NEXT Y
600 RETURN
700 IX = 5
720 IF IX > 5 THEN IX = 1
725 IF IX < 1 THEN IX = 5
740 IF IX = 5 THEN GX = 80:GY=60
750 IF IX = 4 THEN GX = 64:GY=48
755 IF IX = 3 THEN GX = 32:GY=24
760 IF IX = 2 THEN GX = 16:GY=12
765 IF IX = 1 THEN GX = 8:GY = 6
770 XS = 320/GX:YS=240/GY
780 RECT 0,0,319,239,$10
790 FRAME 0,0,319,239, $01
800 FOR X = XS TO 320-XS STEP XS
810 LINE X,0,X,239,$01
820 NEXT X
830 FOR Y = YS TO 240-YS STEP YS
840 LINE 0,Y,319,Y,$01
850 NEXT Y
855 COLOR 7,11
860 LOCATE 3,3:PRINT " ";
861 LOCATE 4,3:PRINT " ";
865 LOCATE 5,3:PRINT " ";
866 LOCATE 6,3:PRINT " ";
870 LOCATE 6,3:PRINT " SELECT GRID: (ARROW KEYS)";
875 COLOR 5:LOCATE 4,4:PRINT GX;" X ";GY;
876 COLOR 10:PRINT " <ENTER TO CHOOSE>";
900 GET K$
910 K = ASC(K$)
920 IF K=157 OR K=17 THEN IX = IX + 1:GOTO 720
930 IF K=145 OR K=29 THEN IX = IX - 1:GOTO 720
940 IF K=13 THEN CLS:RETURN
950 IF K=27 THEN END
960 COLOR 7,11:GOTO 870
8000 GET X$:IF X$<>"" THEN GOTO 150 : REM FLUSH KEYBOARD BUFFER
8010 GET X$:IF X$="" THEN GOTO 8010 : REM WAIT FOR KEY
8020 SCREEN 0:END