Game of Life

Game of Life

Last week I wrote about my friend Mel and how he's been building a chatbot called Hal 9000. Well, I've been building a chatbot of my own – a ChatGPT powered personal assistant to help me create content and code. My chatbot's name is Mel 9000.

Mel 9000 started as off as the Hello World for Python + the ChatGPT API. Just a way for me to talk to ChatGPT – later GPT-4 – the command line. But once I had programatic control, there were a few features I wanted to add. For instance, I found myself asking Mel 9000 questions about code, and copying-and-pasting his answers. I thought, "Sure would be nice if I could save this straight to disk."

I built that functionality during my first ever Hai Hai Twitch stream. This kind of gives you the gist of it – a simple switch that responds to a few pre-baked commands, otherwise the content passes along to GPT-4.

def branch(content):
    if content in ["quit", "exit"]: 
        console.log("Goodbye!")
        sys.exit()
    elif is_save(content.strip()): 
        filename = get_export_filename(content)
        save_content(filename, MESSAGES[-1]["content"])
        return(False)
    elif is_append(content.strip()): 
        filename = get_export_filename(content)
        append_content(filename, MESSAGES[-1]["content"])
        return(False)

So now I can ask GPT-4 to write and save code. One of the first programs I had Mel 9000 create is Conway's Game of Life. If you're unfamiliar with the Game of Life: it's not a "game" in the sense that anyone's playing – except for maybe the cells themselves. "Simulation" might be a more familiar description, as in "Simulation of Life."

It works like this: Picture an infinite chessboard. Each square represents a cell. A cell can either be alive (white) or dead (black). On each turn – or "generation" – a cell's state is determined by the state of its eight neighbors on the previous turn:

  1. If a living cell has less than two live neighbors, it dies from "underpopulation."
  2. If a living cell has 2 or 3 live neighbors, it lives on to the next generation.
  3. If a cell has 4 or more neighbors, it dies by "overpopulation."
  4. Any dead cell with exactly three live neighbors becomes a live cell, via "reproduction."

The Game of Life in action looks something like this:

0:00
/

From these few simple rules, Conway's Game of Life generates surprisingly complex phenomena that can seem to have purpose. For instance, here's Wikipedia's entry on The Glider, a commonly occurring pattern. Don't worry about what this all means – just appreciate the complexity that stems from four bit-flipping rules running over and over again.

Gliders are important to the Game of Life because they are easily produced, can be collided with each other to form more complicated objects, and can be used to transmit information over long distances. Instances of this second advantage are called glider syntheses. For instance, eight gliders can be positioned so that they collide to form a Gosper glider gun.[4] Glider collisions designed to result in certain patterns are also called glider syntheses. Patterns such as blocks, beehives, blinkers, traffic lights, even the uncommon Eater, can be synthesized with just two gliders. It takes three gliders to build the three other basic spaceships, and even the pentadecathlon oscillator.

As my friend Scott said today, "if you have resources and selection pressure, and the ability to introduce change, then the rest sort of cranks itself out given sufficient time."

So anyway... I asked GPT-4 to write some code.

My prompt was:

write a game of life implementation using HTML/JS/CSS. green on black. make it take up the whole window. 

And here's what happened:

0:00
/