; ID: 1958 ; Author: Matt Merkulov ; Date: 2007-03-14 11:34:58 ; Title: Conway's Life: experiments ; Description: Some interesting additional stuff ;Conway's Life: experiments by Matt Merkulov SeedRnd MilliSecs () Const xres=800, yres=600, fsiz=10, cell=30 ; dst - a flag of the detector of stabilization, dstperiod - the greatest distinguished(recognized) period ; Configurations, dstpasses - quantity of checks, rep - a flag of recurrences, bnd - a flag of ; restrictions of a field, visible - display of an organism to the screen, explo - a mode of ; periodic "explosion", xper - frequency of "explosion" in generations, loadorg$ - ; - loading of an organism from a file, search - a mode of search of long-livers (0 - off, ; any positive number - minimal quantity of generations for record in a file) Const dstperiod=3, dstpasses=5, xper=256, bnd=1, visible=1 Const explo=1, xrect=150, yrect=100 ; Const dst=1, search=2000, xrect=7, yrect=7 ; Const dst=1, loadorg $ = "locomot.png", xrect=0, yrect=0 ; Const dst=1, loadorg $ = "virus.png", xrect=0, yrect=0 Const fsiz0=1 Shl fsiz, fsiz1=fsiz0-1, fsiz2 = (fsiz0 Shl fsiz), fsiz3=fsiz2-1 Const xc = (fsiz0-xres) Shr 1, yc = (fsiz0-yres) Shr 1 Const x1 = (xres-xrect) Shr 1, x2 = ((xres+xrect) Shr 1)-1 Const y1 = (yres-yrect) Shr 1, y2 = ((yres+yrect) Shr 1)-1 Global ib, bnk, dbnk, dend, cellq Graphics xres, yres, 32 SetFont LoadFont (" Arial cyr ", 14) buf=CreateImage (xres, yres) ib=ImageBuffer (buf) bnk=CreateBank (fsiz2) dbnk=CreateBank (fsiz2 Shl 2) Dim neig (8) k =-fsiz0-1 For n=0 To 7 If n=3 Then k =-1 If n=5 Then k=fsiz0-1 neig (n) =k k=k+1 + (n=3) Next Dim change (64) For n=0 To 3 Read m $ For nn=0 To 8 change (n*16+nn) =Sgn (Instr (m $, nn)) Next Next Data "3", "0145678"; key rules Data "23", "0245678"; rules for "explosion" ; A file for storage of the generated organism Dim org (xrect, yrect) If search Then f=WriteFile ("longlife.txt") Repeat LockBuffer ib dend =-4 If loadorg $ = "" Then For x=x1 To x2 For y=y1 To y2 If Rand (0,99) fsiz1 And (pos And fsiz1)> 0) Then v = (k And 16) Shr 4 If visible Then x = (pos And fsiz1)-xc y = (pos Shr fsiz)-yc If x>=0 And x =0 And y 0 And search <=gen Then WriteLine f, gen For x=0 To xrect-1 m $ = "" For y=0 To yrect-1 If org (x, y) Then m $ = m $ + "0" Else m $ = m $ + "-" Next WriteLine f, m $ Next WriteLine f, " " End If ; Before generation of a new organism the screen and the buffer of attributes is cleared, and also ; Counters of generations, cells(cages) and the index of a file "interesting" are nulled ; Cells SetBuffer ib Cls SetBuffer FrontBuffer () FreeBank bnk bnk=CreateBank (fsiz2) gen=0 cellq=0 Forever Function putcell (x, y) pos=x+xc + ((y+yc) Shl fsiz) For nn=0 To 8 addr = (neig (nn) +pos) And fsiz3 p=PeekByte (bnk, addr) If p=0 Then dend=dend+4 PokeInt dbnk, dend, addr PokeByte bnk, addr, 65 Else PokeByte bnk, addr, p+1 End If Next PokeByte bnk, pos, PeekByte (bnk, pos) + 15 If visible Then WritePixel x, y,-1, ib ; Increase in the counter of cells(cages) at unit cellq=cellq+1 End Function