Hello everyone,
The Game of Life is one of my favorite topics and is the forerunner
of modern Cellular Automation, Evolutionary Algorithms, Fractals and
Mandlebrot graphics
The ZX81 GAME of LIFE was based on John Conway's article in
Scientific American where he described a virtual reality of cells battling
for survival visible on a computer screen. A few simple rules cause
cells to form dynamic colonies which eat or are eaten by competing
colonies. Some colonies evolve and some are steady state. Some move
and some are static
The 2 rules of the GAME of LIFE state that:
An existing cell survives if surrounded by 2 or 3 neighbors
A new cell is born if surrounded by 3 neighbors
Under all other conditions a cell will die of either of
loneliness or overcrowding.
To conserve memory the ZX version of LIFE uses the screen
both for memory and display. To do this we generate two intermediate
cell states of dying and birth on the screen before executing the rule.
The left and right walls have fixed pattern templates, which make
life interesting and the top and bottom of the screen are stitched
together (it's a closed universe!)
GOODLIFE.P is a particularly prolific ZXLIFE pattern which
will run for 10,000s of generations. It will run right after loading
as it was captured by the Save command.
As the screen is used to store the pattern this is the only way to
save it. If you break the program the pattern is lost and you will
need to reseed the screen.
This is the reason I have added this "S" command so that you
save a LIFE in progress (to TSLIFE.P) . Rename the file after
saving and I am still looking for the BESTLIFE pattern so let me
know if you capture a truly immortal non-repeating pattern.
Try using a diffuser, just a piece of translucent paper, in front of
the monitor screen, to softens the LIFE contours and it resembles a
colony of bacteria or weather patterns.
The ZX81 BASIC and ML program is found here: GOODLIFE.P
The term GOODLIFE was used in a SF by Fred Saberhagen called
Beserker Base. The Beserkers, a race of run-a-muck robots bent
on destroying all organic life in the galaxy, used that name to
identify any human or member of other organic species who in
exchange for sparing their own life were willing to cooperate.
It suggest that self perpetuating inorganic life forms may be
coerced to do the same on our behalf.
While running the program: adjust the speed with the 0-9 keys.
The S key saves a snapshot of the game in TSLIFE.P
The R key breaks and randomizes the screen and walls after
selecting the cell density.
The C key starts the COMPOSE mode controlled with the
following key functions:
W –white background
B – black background
5,6,7,8 - move the cursor N, S, E, W
1,2,3,4 - move cursor diagonally
9 - pen down
0 - pen up
N/L – RUN
Use slow emulation to control cursor speed.
You can break and list the BASIC program lines to view the
how the BASIC shell performs the above functions as well
Initialization and Saving snapshots.
The ML program runs the Game of Life algorithm on the ZX 81
screen contents. It uses a clever scheme of marking cells a grey
color for dying and for birth as intermediate steps quite visible in
slow emulation.
There are different features visible at different speeds. This program
still blows me away after all these years especially when run at high
speed.
The key to long life are the templates on the left and right walls which
are very "prolific" and although one wall sometimes "freezes" the other
wall will fire it up again by bombarding it with it's "spawn".
Without these templates such a small universe would normally quickly
expire. With the right template pattern this Tiny GOL universe is capable
of infinite variation.
GOODLIFE as such is not perfect and still freezes after tens of
thousands of generations when both walls stop producing simultaneously
I think four template walls would make ZX LIFE run indefinitely without
freezing.
The template idea is something new (I think) and reminds me of
theories of clay substrates forming the basis for the evolution of early
life on earth.
ZXLIFE runs great under EightyOne or Xtender or any other emulator
and of course runs fine but slow on the real thing. No special video
routines are used and the resolution is typical of the ZX plot routines.
The annotated ML program is listed here.
;The ZX81 GAME of LIFE by wilf rigter @ 1983
;based on Conway's article in Scientific American
;origin is 4084h
LD HL,(400C) ;HL points to the top of the screen memory
LD DE,0021 ; -/+ 33 bytes to move up/down
LD C,14 ;22 lines
NLINE INC HL ;first cell
LD B,1E ;30 cells per line
NCELL LD A,50 ;initialize cell counter in A with 50h
CP (HL) ;this part checks block of 8 neighboring cells
ADC A,D ;increments ">80h" neighbor counter in A
INC HL ;top middle
CP (HL)
ADC A,D
INC HL ;top right
CP (HL)
ADC A,D
ADD HL,DE ;right
CP (HL)
ADC A,D
ADD HL,DE ;bottom right
CP (HL)
ADC A,D
DEC HL ;bottom middle
CP (HL)
ADC A,D
DEC HL ;bottom right
CP (HL)
ADC A,D
SBC HL,DE ;left
CP (HL)
ADC A,D
INC HL ;middle cell
CP (HL)
JR NC 06 ;if middle cell is >56
CP 55
JR NZ 0C
LD (HL),88 ;mark for birth
CP 55
JR Z 06
CP 56
JR Z 02
LD (HL),08 ;mark as dying
XOR A
SBC HL,DE
DJNZ NCELL
INC HL ;advance to the next line
INC HL ;skip EOL character
DEC C ;dec line counter
JR NZ NLINE ;last line?
;now screen memory is tested for
;dying and birth marks
;first execute dying cells
LD DE,0880 ;dying mark in D and death in E
MARK LD HL,(400C) ;top of screen
LD BC,03B4 ;cell counter
NMARK INC HL ;first cell
LD A,(HL) ;test cell
CP D ;is it marked cell? ie CHR$ 08
JR NZ NODIE ;skip if not marked
LD (HL),E ;finish the birth/death cycle
NOMRK DEC C ;dec cell counter
JR NZ NMARK ;next cell
DEC B ;next cell
JR NZ NMARK ;next cell
;the same routine is used for birth
XOR A ;now execute the birth cycle
CP E ;did we already do the births?
JR Z END ;If birth and death done then bye
LD DE,8800 ;birth mark in D and birth in E
JR MARK ;go forth and deliver
END LD C,20 ;it's a closed universe
SBC HL,BC ;so the last line (32 chars)
LD DE,(400C) ;is copied to the top line
LDIR ;while the top line is copied
EX DE,HL :to the bottom line thereby
LD C,21 ;stitching the top and bottom
LDIR ;of the screen together like
RET ;a cylinder