Conway's Life, Wikipedia, um.

Coders forum. Discuss techniques, swap code snippets, ask for help etc. relating to all forms of software development.
Post Reply
User avatar
zip accident
Sheepie Whore
Sheepie Whore
Posts: 13928
Joined: Sun Feb 20, 2005 1:58 pm 0
Location: Bristol, UK

Conway's Life, Wikipedia, um.

Post by zip accident »

Rules

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

Any live cell with fewer than two live neighbours dies, as if by underpopulation.
Any live cell with two or three live neighbours lives on to the next generation.
Any live cell with more than three live neighbours dies, as if by overpopulation.
Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

These rules, which compare the behavior of the automaton to real life, can be condensed into the following:

Any live cell with two or three live neighbours survives.
Any dead cell with three live neighbours becomes a live cell.
All other live cells die in the next generation. Similarly, all other dead cells stay dead.

The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed, live or dead; births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick.[nb 1] Each generation is a pure function of the preceding one. The rules continue to be applied repeatedly to create further generations.
Is it just me? :lol: :twisted:
"My way is the way of not fighting":- the book of Enter the Dragon.
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27258
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Conway's Life, Wikipedia, um.

Post by gilesgoat »

Even better everyting can be described/done in ONE SINGLE LINE : https://aplwiki.com/wiki/Conway%27s_Game_of_Life
Giles the billy goat
"Baa"
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27258
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Conway's Life, Wikipedia, um.

Post by gilesgoat »

gilesgoat wrote:Even better everyting can be described/done in ONE SINGLE LINE : https://aplwiki.com/wiki/Conway's_Game_of_Life
https://aplwiki.com/wiki/Conway's_Game_of_Life
Giles the billy goat
"Baa"
User avatar
zip accident
Sheepie Whore
Sheepie Whore
Posts: 13928
Joined: Sun Feb 20, 2005 1:58 pm 0
Location: Bristol, UK

Re: Conway's Life, Wikipedia, um.

Post by zip accident »

My query was related to this bit:
Any live cell with two or three live neighbours survives.
Any dead cell with three live neighbours becomes a live cell.
All other live cells die in the next generation. Similarly, all other dead cells stay dead.
It may not matter on current processors, but on the 68000 or z80, that sort of inefficiency would make a program slow.

Conway's Life is troublesome to program because you need the neighbours from the previous generation, so you can't just itterate over the screen altering stuff as you pass, because if you did you'd change some neighbours that you needed for calculations on cells you hadn't got to yet. My solution was two arrays mapped to the screen, which alternated between being the previous generation and the current one, then write the screen when the current generation was finished. That being so, I think it was more effective to write each cell once, rather than write every cell to dead then write in the live ones.

So, my version would be:

Any cell with 0,1,4,5,6,7 or 8 neighbours is dead.
Any cell with 3 neighbours is alive.
Any other cell (which can only have 2 neighbours) that was alive is alive.
A cell with 2 neighbours that was dead is dead.

There are more lines, but less testing, and it should be faster.
"My way is the way of not fighting":- the book of Enter the Dragon.
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27258
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Conway's Life, Wikipedia, um.

Post by gilesgoat »

As far as I know ANY "cellular automata" where you have some rules as "Generation X+1 = F ( Generation X ) " requires TWO arrays "OLD" and "NEW" and then you swap PTRs between the two.

You compute "NEW" from "OLD" then "NEW" becomes "OLD" and "OLD" "NEW" and you repeat.

MAYBE , not able to think it "on the fly" now, MAYBE you can do something by "caching" only 9 lines of "NEW" at the time but then I suppose you'd had to copy those 9 lines from "new" to old.

The easiest route is always to have 2 arrays of "cell states".
Giles the billy goat
"Baa"
User avatar
GoatFoam
Baaaaa!
Baaaaa!
Posts: 1255
Joined: Tue Dec 12, 2006 11:05 am 0
Location: Brizzle
Contact:

Re: Conway's Life, Wikipedia, um.

Post by GoatFoam »

I know there are life acceleration algorithms based on hashing that allow reasonable speed on unreasonably large grids. Also sparse representations that allow unlimited scaling.

I suspect that they would be too memory hungry for small computers though.
User avatar
zip accident
Sheepie Whore
Sheepie Whore
Posts: 13928
Joined: Sun Feb 20, 2005 1:58 pm 0
Location: Bristol, UK

Re: Conway's Life, Wikipedia, um.

Post by zip accident »

GoatFoam wrote:I know there are life acceleration algorithms based on hashing that allow reasonable speed on unreasonably large grids. Also sparse representations that allow unlimited scaling.

I suspect that they would be too memory hungry for small computers though.
What would you consider to be a small computer in this context?
"My way is the way of not fighting":- the book of Enter the Dragon.
User avatar
GoatFoam
Baaaaa!
Baaaaa!
Posts: 1255
Joined: Tue Dec 12, 2006 11:05 am 0
Location: Brizzle
Contact:

Re: Conway's Life, Wikipedia, um.

Post by GoatFoam »

the z-80 mentioned above is definitely too small, maybe the 68k. Hash life implementations were practical on the 486 DX-4 I had in the mid-late 90s.
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27258
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Conway's Life, Wikipedia, um.

Post by gilesgoat »

Ok this is another challenge for me .. do a life 256x192 on a ZX then .. I never done it ...
Giles the billy goat
"Baa"
User avatar
WiteWulf
Sheepie Whore
Sheepie Whore
Posts: 10125
Joined: Mon Aug 23, 2004 11:20 am 0
PSN: WiteWulf
Location: Loughborough(ish)

Re: Conway's Life, Wikipedia, um.

Post by WiteWulf »

I wrote a very simple Mandelbrot renderer in OPL on a Psion 3a 30 years ago. Took about 2hrs to render a basic fully zoomed out image (480x160), iirc. The 3a had a 7.68MHz NEC V30H CPU :lol:
:::G:::

PSN: WiteWulf
Switch: SW-3941-2878-7584
Steam: WITEWULF66
User avatar
zip accident
Sheepie Whore
Sheepie Whore
Posts: 13928
Joined: Sun Feb 20, 2005 1:58 pm 0
Location: Bristol, UK

Re: Conway's Life, Wikipedia, um.

Post by zip accident »

WiteWulf wrote:I wrote a very simple Mandelbrot renderer in OPL on a Psion 3a 30 years ago. Took about 2hrs to render a basic fully zoomed out image (480x160), iirc. The 3a had a 7.68MHz NEC V30H CPU :lol:
No offence intended, but OPL must have been horribly bad, a basic PC could do that faster.
"My way is the way of not fighting":- the book of Enter the Dragon.
User avatar
koogy
Baaa!
Baaa!
Posts: 475
Joined: Thu Aug 31, 2006 11:16 am 0

Re: Conway's Life, Wikipedia, um.

Post by koogy »

i figured this thread bump would be about this because o_O

https://oimo.io/works/life/
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27258
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Conway's Life, Wikipedia, um.

Post by gilesgoat »

WiteWulf wrote:I wrote a very simple Mandelbrot renderer in OPL on a Psion 3a 30 years ago. Took about 2hrs to render a basic fully zoomed out image (480x160), iirc. The 3a had a 7.68MHz NEC V30H CPU :lol:
I can't remember precisely but in SuperBasic at 256x256 resolution on a Sinclair QL @8Mhz took about 8 .. 10 hours to render a mandelbrot !!!
Giles the billy goat
"Baa"
Post Reply