MINILIFE:Â BASIC Tenliners Contest 2019 entry
Back to my personal theme for 10-liner entries — classic BASIC algorithms. It’s hard to get more classic than Conway’s Game of Life. This simple game/simulation was covered so times from many perspectives in Byte Magazine, Creative Computing, and so on. I used the algorithm as described by Mark D. Niemiec in the January 1979 issue of Byte for my 10-liner.
My program lets you edit the starting playfield configuration, run the simulation, then optionally stop the sim to edit the playfield before continuing. At 80 characters per line, this program would fit in PUR-80, the most restrictive contest category. But after writing it I learned that the contest rules say that the PUR-80 category is limited to versions of BASIC that ship with the computer — e.g. Atari BASIC for the Atari 8-bit line. Since I wrote MINILIFE in TurboBASIC XL, and can’t convert it to Atari BASIC without making it significantly longer, I will submit it to the PUR-120 category. Boo.
GR.3 HY=10:'MAX 19 - playfield height HX=20:'MAX 39 - playfield width. Bigger playfield makes it slower. DIM OLD(HY+1,HX+1),NW(HY+1,HX+1):'arrays for old and new playfield 'draw bounding box COLOR 3:PLOT 0,0:DRAWTO HX+1,0:DRAWTO HX+1,HY+1:DRAWTO 0,HY+1:DRAWTO 0,0 ?"MINILIFE" 'Edit cells with joystick. DO X=1:Y=1:?"Edit mode. Place cells then SPACE." POKE 764,255:'clear keyboard buffer WHILE PEEK(764)<>33:'until SPACE is pressed... COLOR NW(Y,X):PLOT X,Y:'show cell in current position S=STICK(0) Y=Y+((S=13)-(S=14)):'move up/down X=X+(S=7)-(S=11):'move left/right IF X<1:X=HX:ENDIF:'stay in bounds IF Y<1:Y=HY:ENDIF IF X>HX:X=1:ENDIF IF Y>HY:Y=1:ENDIF IF(STRIG(0)=0) NW(Y,X)=NOT NW(Y,X):'toggle cell on/off PAUSE 3 ENDIF COLOR 2:PLOT X,Y:'show cursor PAUSE 4 WEND 'now run the sim IT=0:?"Generating life. SPACE to stop." POKE 764,255 DO 'draw the current colony FOR Y = 1 TO HY FOR X = 1 TO HX COLOR 3:PLOT X,Y OLD(Y,X)=NW(Y,X) COLOR OLD(Y,X) PLOT X,Y NEXT X NEXT Y IF PEEK(764)=33:EXIT:ENDIF:'SPACE = back to editor 'calculate the next generation. Read the Byte article :) FOR Y = 1 TO HY FOR X = 1 TO HX SUM=OLD(Y-1,X-1)+OLD(Y-1,X)+OLD(Y-1,X+1)+OLD(Y,X-1)+OLD(Y,X+1)+OLD(Y+1,X-1)+OLD(Y+1,X)+OLD(Y+1,X+1) IF SUM=3 NW(Y,X)=1 ELSE IF SUM=2 NW(Y,X)=OLD(Y,X) ELSE NW(Y,X)=0 ENDIF ENDIF NEXT X NEXT Y IT=IT+1:?IT:'iteration counter LOOP LOOP










