{$G+}{$X+}{$N+}{$E+} {$B-}{$D-}{$L-} {$M 16384,200000,655360} program ideatest; uses dos, crt, graph, mygraph, svgabgi; type maparray = array[0..319,0..199] of byte; var map1,map2:^maparray; i,j,k,l,x,y,xx,yy,c,ct,alives,empties,adv:integer; spawn,kill:boolean; Procedure FlushKey; { Clears any key strokes in the key- } { board buffer so a couple of key } var { presses don't race you through program. } Regs : Registers; begin Regs.AH := $01; { AH=1: Check for keystroke } Intr($16,regs); { Interupt $16: Keyboard services} IF (regs.Flags and $0040) = 0 then { if chars in buffer } REPEAT Regs.AH := 0; Intr($16,Regs); Regs.AH := $01; Intr($16,Regs); Until (regs.flags and $0040) <> 0; end; BEGIN dispose(screen); new(map1); new(map2); graphitV; for i:=0 to 319 do for k:=0 to 199 do map1^[i,k]:=random(0); c:=0; ct:=1; map1^[50,50]:=1; map1^[51,50]:=1; map1^[50,51]:=1; map1^[51,51]:=1; map1^[149,149]:=2; map1^[148,149]:=2; map1^[149,148]:=2; map1^[148,148]:=2; for i:=0 to 319 do for k:=0 to 199 do putpixel(i,k,map1^[i,k]); { readkey;} while not keypressed do begin inc(c); if c>=1 then begin c:=0; ct:=3-ct; { Setting CreatureTypecode } end; for i:=0 to 319 do for k:=0 to 199 do begin { First take a tally of adjacent spaces } alives:=0; empties:=0; for x:=i-1 to i+1 do for y:=k-1 to k+1 do begin xx:=x; if xx<0 then xx:=xx+320; if xx>=320 then xx:=xx-320; yy:=y; if yy<0 then yy:=yy+200; if yy>=200 then yy:=yy-200; if (i<>xx) or (k<>yy) then begin if (map1^[xx,yy]=ct) then inc(alives) else inc(empties); end; end; {if (ct=2) then adv:=2 else adv:=0;} { Then figure out what to do with the current one } if map1^[i,k] <> ct then {map1^[i,k] = 0 then} begin { This is empty space, so check to see if it comes to life } spawn:=false; case empties of 1:if ((adv>1) and (random(4)=0)) then spawn:=true; 2:begin if random(4)=0 then spawn:=true; if ((adv>0) and (random(5)=0)) then spawn:=true; end; 3:begin if random(3)=0 then spawn:=true; if ((adv>0) and (random(5)=0)) then spawn:=true; end; 4:if random(2)=0 then spawn:=true; 5:if random(3)=0 then spawn:=true; 6:if random(4)=0 then spawn:=true; end; if spawn then map2^[i,k]:=ct else map2^[i,k]:=map1^[i,k]; end else if map1^[i,k] = ct then begin { This space is alive and awake, see if it dies } kill:=true; case alives of 2:if random(6)>0 then kill:=false; 3:if random(30)>0 then kill:=false; 4:kill:=false; 5:begin if random(30)>0 then kill:=false; if ((adv=0) and (random(5)=0)) then kill:=true; end; 6:if random(5)>0 then kill:=false; end; if kill then map2^[i,k]:=0 else map2^[i,k]:=map1^[i,k]; end else begin { This creature type is sleeping, so just copy it } map2^[i,k]:=map1^[i,k]; end; end; map2^[50,50]:=1;map2^[50,51]:=1;map2^[51,50]:=1;map2^[51,51]:=1; map2^[149,149]:=2;map2^[148,149]:=2;map2^[149,148]:=2;map2^[148,148]:=2; map1^:=map2^; for i:=0 to 319 do for k:=0 to 199 do {putpixel(i,k,map1^[i,k]);} mem[$A000:i+(k shl 8)+(k shl 6)]:=map1^[i,k]; {readkey;} repeat until i<>mem[0:$46C]; i:=mem[0:$46C]; end; flushkey; closegraph; END.