DEV Community

Cover image for Share Your Conway's Game Of Life
Ben Lovy
Ben Lovy

Posted on

Share Your Conway's Game Of Life

Sadly, John Horton Conway has passed away. While Conway's contributions to computational mathematics over the years are numerous and eclectic, many aspiring coders are introduced to his work via Conway's Game of Life, a cellular automaton that's relatively simple to implement.

In the Game of Life, you provide an initial state, or seed, to a square grid of cells. Each cell is either "on" or "off", and the next state of the grid is calculated via these rules, as stated on Wikipedia:

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

As this is relatively simple to write logic for, many programmers take a stab at implementing such a program early in their careers. Here's mine on GitHub, from July 2017, as one of my first Rust programs - but not terribly interesting to look it as it just renders world states in text to the terminal. However, it does demonstrate how trivial the core logic is to write:


//tick_cell takes a Coord and a World and returns the next state of the cell
fn tick_cell(c: &Coord, w: &World) -> bool {
    let s = moore_sum(c, w);
    if get_cell(c, w) {
        match s {
            2 | 3 => true, //ALIVE
            _ => false, //overcrowded or starved
        }
    } else {
        match s {
            3 => true, //3 gives birth
            _ => false, //barren
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Do you have a Game of Life to show us? Bonus points for an implementation we can play with - my entry must be downloaded and compiled, but I'm sure some of you web-dev-y types have something more interactive!

What are some of your favorite seeds? Are there other cellular automata that interest you?

Alternatively, what other John Conway work has inspired you? According to this redditor, Conway was frustrated that the Game of Life was his most well-known contribution. What else do you remember him for?

Image: wikimedia commons

Top comments (22)

Collapse
 
bch77 profile image
bch77

I have an implementation that I made on Shadertoy It is very playable-with in a desktop browser (read the code for extensive usage notes). It's somewhat limited in field size, however.

I am so sad and angry that COVID-19 took JHC. I remember him for various things beyond Life, including his analysis of the Rubik's cube, Sprouts, and his work with uniform polychora. He was such a shining light and will be hugely missed.

Collapse
 
franky47 profile image
François Best • Edited

Here's mine, with a genetic twist: cells have color genes, that are passed from their three parents. It creates a colorful battle of color factions over time, I built it while learning Rust:

genetic-life.surge.sh

Source: github.com/franky47/genetic-life/b...

Collapse
 
gypsydave5 profile image
David Wickes • Edited

The greatest solution I've ever seen is written in APL.

←{                                  
    ↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ 
}

If you're anything like me you'll try and implement the same reasoning in a different language.

Collapse
 
deciduously profile image
Ben Lovy

I am utterly fascinated by APL/J/family. Just need more hours in the week...

Collapse
 
krthr profile image
Wilson Tovar
Collapse
 
deciduously profile image
Ben Lovy

I just started learning Crystal this week! Definitely taking a look, thanks for sharing.

Collapse
 
krthr profile image
Wilson Tovar

Crystal is amazing. I'm love with that language <3

Collapse
 
rogerzanoni profile image
Roger Zanoni

Very old (7 years ago, every time I comment here I feel older :) and not very efficient:

gist.github.com/rogerzanoni/6381027

It's written in QML and if we change the import to at least QtQuickt 2.0 and world width, height to 100, it looks like this:

gameoflife

Collapse
 
karataev profile image
Eugene Karataev

Here's my Life game. And the repo.

I wrote it 5 years ago when just started my path in frontend development. AngularJS, ES5, script tags, no bundlers...

RIP professor Conway.

Collapse
 
krikchaip profile image
Krikchai Pongtaveewould

Just recently finished one. Check this out!
demo: krikchaip.github.io/game-of-life
source: github.com/krikchaip/game-of-life

Collapse
 
deciduously profile image
Ben Lovy

This is a nice, clean implementation! Thanks for sharing.

Collapse
 
gklijs profile image
Gerard Klijs

I made 2d and 3d versions learning rust with web assembly. Online at gameoflife2d.gklijs.tech/ and gameoflife3d.gklijs.tech/. Code at github.com/gklijs/game-of-life.

Collapse
 
kosich profile image
Kostia Palchyk

Sad news. One of many upcoming, I'm afraid.

Here is a playlist with John Conway interviews made by Numberphile channel
youtube.com/playlist?list=PLt5AfwL...

Collapse
 
aka_dude profile image
Andrew Andersen

I wrote mine to try using OpenCL, so it uses GPU for simulation, but I didn't bother myself with proper rendering. Also, host language is Rust :)
github.com/Mr-Andersen/game-of-lif...

Collapse
 
dineshgdk profile image
Dinesh Kumar Gnanasekaran

I wrote Game of Life in JS. Check out the link, you can even play with it
dinesh-gdk.github.io/Game-Of-Life/

Collapse
 
deciduously profile image
Ben Lovy

Great implementation, thank you for sharing!

Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more