jms@antares.UUCP (joe smith) (08/17/88)
After reading the August issue of Scientific American, I had to try writing a version of HodgePodge just to see it work. The following is a quick hack in AmigaBasic, based on the instructions found in the "Computer Recreations" section. (If anyone has the full details of this program, please mail them to me. I was working from the "brief recipe", and had to make certain assumptions to get it to work.) ' HodgePodge - as described in Aug-88 Scientific American. ' as interpreted by Joe Smith from the cursory description ' in the "Computer Recreations" section (pages 104-106) DEFINT a-z wid=30 : hit=20 :' width & height of board siz=8 :' size of each square on board n=100 : k1=2 : k2=3 :' parameters PRINT "HodgePodge using N=100, K1=2, K2=3" INPUT "Enter a number from 1 to 10 for G :";g DIM b1(wid,hit),b2(wid,hit) :'before and after boards SCREEN 1,320,200,5,1 :' lores, 32 colors WINDOW 2,"HodgePodge G ="+STR$(g),(0,0)-(311,180),0,1 WINDOW OUTPUT 2 GOSUB randomscreen looptop: FOR j=1 TO hit-1 FOR i=1 TO wid-1 b=0 : a=0 IF b1(i-1,j) = n THEN b=b+1 IF b1(i+1,j) = n THEN b=b+1 IF b1(i,j-1) = n THEN b=b+1 IF b1(i,j+1) = n THEN b=b+1 IF b1(i,j) > 0 THEN a=a+1 IF b1(i-1,j) > 0 THEN a=a+1 IF b1(i+1,j) > 0 THEN a=a+1 IF b1(i,j-1) > 0 THEN a=a+1 IF b1(i,j+1) > 0 THEN a=a+1 s=b1(i-1,j)+b1(i+1,j)+b1(i,j-1)+b1(i,j+1)+b1(i,j) '"a" is the number of infected cells (including ill ones). '"b" is the number of ill cells. '"s" is the sum of states of cells in von Neumann neighborhood. IF b1(i,j) < 1 THEN b2(i,j) = INT(a/k1)+INT(b/k2) :'healthy->infected IF b1(i,j) > 0 THEN b2(i,j) = INT(s/a)+g :'infected gets sicker IF b1(i,j) = n THEN b2(i,j) = 0 :'ill -> healthy IF b2(i,j) > n THEN b2(i,j) = n :'limit on infection CALL drawdot(i,j,b2(i,j)) :'X,Y,COLOR NEXT i NEXT j sick=0 : ill=0 FOR j=1 TO hit-1 :'j=0 and j=hit are borders FOR i=1 TO wid-1 :'as are i=0 and i=wid b1(i,j)=b2(i,j) :' copy new results to board IF b1(i,j) = n THEN ill = ill + 1 IF b1(i,j) > 0 AND b1(i,j) < n THEN sick = sick + 1 NEXT i NEXT j gens = gens + 1 GOSUB stats :'Output sick, ill counts GOTO looptop initpalette: PALETTE 0,0!,0!,0! 'Black = healthy PALETTE 1,0!,1!,0! 'Green PALETTE 2,.2,1!,0! PALETTE 3,.4,1!,0! PALETTE 4,.6,1!,0! PALETTE 5,.8,1!,0! PALETTE 6,1!,1!,0! 'Yellow PALETTE 7,1!,.8,0! PALETTE 8,1!,.6,0! PALETTE 9,1!,.4,0! PALETTE 10,1!,.2,0! PALETTE 11,1!,0!,0! 'Red PALETTE 12,1!,0!,.2 PALETTE 13,1!,0!,.4 PALETTE 14,1!,0!,.6 PALETTE 15,1!,0!,.8 PALETTE 16,1!,0!,1! 'Magenta PALETTE 17,.8,0!,1! PALETTE 18,.6,0!,1! PALETTE 19,.4,0!,1! PALETTE 20,.2,0!,1! PALETTE 21,0!,0!,1! 'Blue PALETTE 22,0!,.2,1! PALETTE 23,0!,.4,1! PALETTE 24,0!,.6,1! PALETTE 25,0!,.8,1! PALETTE 26,0!,1!,1! 'Cyan PALETTE 27,.2,1!,1! PALETTE 28,.4,1!,1! PALETTE 29,.6,1!,1! PALETTE 30,.8,1!,1! PALETTE 31,1!,1!,1! 'White = ill RETURN randomscreen: GOSUB initpalette FOR i=0 TO 31 :'draw sample color bar LINE (i*siz,(hit+1)*siz)-STEP(siz-1,siz-1),i,bf NEXT i LINE (siz/2,siz/2)-(wid*siz+siz/2,hit*siz+siz/2),16,b sick=0 : ill=0 : gens=0 FOR j=1 TO hit-1 FOR i=1 TO wid-1 b1(i,j)=INT(RND*n) CALL drawdot(i,j,b1(i,j)) IF (b1(i,j) > 0) THEN sick=sick+1 NEXT i NEXT j LOCATE 1,32 : PRINT "Healthy" LOCATE 3,32 : PRINT "Ill" LOCATE 5,32 : PRINT "Infected" LOCATE 7,32 : PRINT "Generation" GOSUB stats RETURN stats: LOCATE 2,32 : PRINT (wid-1)*(hit-1) - (sick+ill) LOCATE 4,32 : PRINT ill LOCATE 6,32 : PRINT sick LOCATE 8,32 : PRINT gens RETURN SUB drawdot(i,j,col) STATIC SHARED n,siz 'Only healthy cells show up a color=0 (black). 'Only ill cells show up as color=31 (white). 'The remaining 30 colors are mean infected. 'if col=0, c=0 : if col=1, c=1 'if col=n-1, c=30 : if col=n, c=31 c = INT((col*30 + n-1 - 30)/(n-1)) LINE (i*siz,j*siz)-STEP(siz-1,siz-1),c,bf END SUB