A downloadable tool

THE GAME OF LIFE (OPTIMIZED) 10LINER FOR ZX81

Author: Ernesto Uriburu

Category: WILD 

The Game of Life, or simply known as “Life”, is a cellular automaton devised by the British mathematician John Horton Conway in 1970. It requires no user input and therefore is a zero-player game; its evolution is determined by its initial state.

The universe of the Game of Life is an infinite, two-dimensional grid of cells, each of which is in one of two possible states: live or dead. Every cell interacts with its eight surrounding neighbors, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

1. Any live cell with fewer than two live neighbors dies, as if by underpopulation.

2. Any live cell with two or three live neighbors lives on to the next generation.

3. Any live cell with more than three live neighbors dies, as if by overpopulation.

4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules to every cell in the seed; births and deaths occur simultaneously and each generation is a pure function of the preceding one. The rules continue to be applied repeatedly to create further generations. Live cells are represented by inverse spaces over a white background of empty or dead cells. 

To accomplish that in only ten lines the program uses an array, in four parts, the first one being the actual status and the second the next generation being calculated. To speed up the process the “world” matrix is limited to the upper half of the screen and a mask is built on a third part of the array to mark those cells that are alive or neighboring an alive cell. This way it doesn't process cells that would not change in this generation. A fourth array is used to reset the second and third ones every new generation. This is all performed in a single loop as a way to save lines.

The initial pattern is provided in the listing as string A$ in line 20. Feel free to test any other pattern to see the “evolution”; there are some interesting examples in the Wikipedia article at https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life#Examples_of_patterns 

Keep the initial pattern between A$(99 TO 286) to give room in the array for the second generation to grow up- or downward and to calculate the neighbors.

Included is the “Light Weight Space Shift” pattern that will walk from left to right on the screen. The listing can easily be modified to include an INPUT statement in line 20 to make it interactive without editing the listing; just preserve the range of the string as in the original line. The initial pattern is always fitted from the second place of the third row. It will process the second row every time and will search for neighbors in the first one but won't process life over the first one. This is to keep the process into the array. The bottom rows are treated in a similar way. At the sides patterns will just past through, jumping down a row from the right border or up from the left one as it's a one-dimensional array. 

Using strings instead of numerical values makes this difficult to read and may be slower but will dramatically increase the printing speed on screen on line 30.

Line 50 checks the existence of an alive cell in advance to mark their neighbors for evaluation.

Line 60 checks for the marks and skips cells not marked to avoid processing the cells not alive and without alive neighbors that don't have any chance to modify their status.

Line 70 applies the game rules, calculating the sum of living neighbors. That operation is made twice in the line just to save a line. This cost me falling to the WILD category as I ended up with an extremely long sentence and with a speed penalty. Just remember that a ZX81 can't use multiple statements separated by the colon ( : ) as in other BASIC dialects. This program was optimized to fit in 10 lines and that harmed performance somewhat.

Recognition:

I must express my gratitude to Juan José Ponteprino who accompanied during late nights through WhatsApp, providing ideas, debugging and testing.

Install instructions

The program runs on an original ZX81 with at least 16Kb of RAM or compatible clones, as well as in the EightyOne emulator, available at https://sourceforge.net/projects/eightyone-sinclair-emulator/ 

To run it, be sure to configure the RAM pack option at Options / Hardware… (F6).

To load the program just drag and drop the LIFE10Liner.P file into the emulator and wait for a few seconds.

If it doesn't load automatically, type:  J  shift+P shift+P  ENTER  (it should read: LOAD ""), then type R and ENTER ( RUN ENTER).

Download

Download
Life10Liner.p 3 kB
Download
THE GAME OF LIFE 10LINER FOR ZX81.pdf 82 kB
Download
THE-GAME-OF-LIFE-10LINER-FOR-ZX81.txt 4 kB

Leave a comment

Log in with itch.io to leave a comment.