Game of Life in 6 hours

6 de abril de 2025 a las 10:40

One evening after falling down a YouTube rabbit hole of cellular automata videos, I found myself captivated by Conway’s Game of Life. There’s something mesmerizing about watching complex patterns emerge from just four simple rules. After watching a particularly good explanation, I remember thinking, “Hey, I’m sure I can develop that in just one afternoon.” And that’s exactly what I decided to do. You can try it yourself here: Game of Life

I gave myself a personal challenge: implement Conway’s Game of Life in Godot within 6 hours. No pressure, just me and some coffee.

The rules themselves are deceptively simple:
- Lonely cells with fewer than two neighbors die
- Cells with two or three neighbors survive
- Overcrowded cells with more than three neighbors die
- Dead cells with exactly three neighbors come to life

Getting these basic rules working wasn’t particularly difficult, but making everything work smoothly and efficiently? That’s where the fun began.

One of the first challenges I tackled was the “wrap-around” feature. I wanted cells at the edge of the grid to connect with the opposite side, I wasn’t sure if the “infinite grid” was the way to go for a couple hours development, so I decided to create the illusion of an infinite world. Using the modulo operation seemed straightforward at first, but I quickly discovered that handling negative indices required some careful thought. After some debugging and with help of some coffee, I finally got it working:

var nx = (x + i + grid_width) % grid_width
var ny = (y + j + grid_height) % grid_height

Offseting by the grid size prevented the negative indices.

As my grid size grew, I noticed the simulation getting sluggish, which pushed me to implement some optimizations. I used a double buffering technique to avoid update conflicts and later improved performance by only recalculating cells near living ones. Dead zones stay dead until something interesting happens nearby, after all.

Integrating the game into my Django website presented its own set of challenges. Getting the Godot WebAssembly export to play nicely within an iframe took some tinkering with CORS policies and content security settings. I spent a good hour just figuring out why my iframe refused to load until I got the right CSP headers.

I’m pretty proud that I managed to complete the core game within my self-imposed 6-hour limit. There’s something satisfying about setting a tight deadline and actually meeting it. The minimalist constraint forced me to focus on what really mattered.

But of course, ideas keep flowing. I’m now planning to add cell aging, where cells change color as they age, giving a visual history to the simulation. I’m also excited about introducing “predator” cells that follow different rules, creating an interesting predator-prey dynamic within the simulation.

Looking back, this quick project exercised quite a range of skills - from algorithm optimization to web integration and rapid prototyping. But more than that, it was just plain fun to watch these digital cells live, die, and create unexpected patterns before my eyes, there’s a special satisfaction in building your own version. And doing it all in just 6 hours? That’s just the cherry on top.