Game of Life.
Posted: Mon Sep 22, 2014 1:33 am
Here's a rough conversion (which is partially bug-fixed) of the Game of Life thing that I entered in the 2013 CSS CGC for the Sinclair ZX81. It's quite slow, of course, and requires an accelerator real or emulated.
Press the any key to start from generation one again.
For those who don't want to type, I've put a compressed disk image here. the file beginning with b. is the Blitz! compiled version.
Regards,
Shaun.
Code: Select all
0 r=rnd(0):poke 53280,0:poke 53281,0:print"{clear}{light gray}";:gosub 63990:gosub 4:goto 28
1 rem cleargrid()
2 for i=z to h:for j=z to w:g(i,j)=z:next j,i:return
3 rem fillarray()
4 for i=z to a:for j=o to b:r=int(rnd(ti)*x):if r<d then g(i,j)=o
5 next j,i:return
6 rem showarray()
7 for i=z to h:for j=z to w:if g(i,j) then print "0";:goto 9
8 print" ";
9 next j,i
10 rem checkneighbour()
11 for j=o to b:n=z:if g(z,j) and g(z,j-o) then n=n+o
12 if g(z,j) and g(z,j+o) then n=n+o
13 if g(z,j) and g(o,j) then n=n+o
14 if g(z,j) and g(o,j+o) then n=n+o
15 if g(z,j) and (n<e or n>d) then g(z,j)=z
16 if g(z,j)=z and n=d then g(z,j)=o
17 next j:for i=o to a:for j=o to b:n=z:if g(i,j) and g(i-o,j) then n=n+o
18 if g(i,j) and g(i-o,j-o) then n=n+o
19 if g(i,j) and g(i-o,j+o) then n=n+o
20 if g(i,j) and g(i+o,j) then n=n+o
21 if g(i,j) and g(i+o,j+o) then n=n+o
22 if g(i,j) and g(i+o,j-o) then n=n+o
23 if g(i,j) and g(i,j-o) then n=n+o
24 if g(i,j) and g(i,j+o) then n=n+o
25 if g(i,j) and (n<e or n>d) then g(i,j)=z
26 if g(i,j)=z and n=d then g(i,j)=o
27 next j,i
28 g=g+o:print"{home}generation:"g:get a$:on-(a$="")goto 7:gosub 3:g=0:print"{clear}":goto 28
63990 rem initialise()
63997 dim g(22,39), g, o, x, s, h, w, a, b, t, e, d, z, a$
63998 o=1: x=8: s=6: h=22: w=39: a=h-o: b=w-o: t=50: e=2: d=3: gosub 1
63999 return
For those who don't want to type, I've put a compressed disk image here. the file beginning with b. is the Blitz! compiled version.
Regards,
Shaun.