conways-gol
is a Conway's Game of Life implementation using Go and OpenGL with go-gl, and was developed as part of a tutorial I wrote on OpenGL with Go.
To follow the tutorial and learn OpenGL with Go by implementing Conway's Game of Life for yourself, check out:
- Part 1: Hello, OpenGL: Install and Setup OpenGL and GLFW, Draw a Triangle to the Window
- Part 2: Drawing the Game Board: Make a Square out of Triangles, Draw a Grid of Squares covering the Window
- Part 3: Implementing the Game: Implement Conway's Game
The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.
The "game" is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts with the Game of Life by creating an initial configuration and observing how it evolves, or, for advanced "players", by creating patterns with particular properties. [1]
The premise of the game is that each cell on the grid is, at any time, either dead or alive. The state of each cell is determined using the following rules:
- Any live cell with fewer than two live neighbours dies, as if caused 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.
For the full rules, check Wikipedia.
You can download and build directly from source like so:
$ go get github.com/KyleBanks/conways-gol
$ conways-gol
conways-gol
takes a few optional parameters:
The -columns
and -rows
parameters dictate the size of the game board.
$ conways-gol -columns 100 -rows 100
Each time conways-gol
is launched, it uses a seed value to randomize the state of the game. The -seed
parameter allows you to fix that value to replay the exact same simulation. For example, a -seed
value of 9000
will always produce an identical game.
$ conways-gol -seed 9000
In addition to the -seed
, the -threshold
is critical in determining the outcome of the game. The -threshold
is a percentage, between 0.0
and 1.0
that dictates the chance of each individual cell starting alive or dead. For instance, if the -threshold
is 0.15
, it means that each cell has a 15%
chance of starting the game alive.
$ conways-gol -threshold 0.1
The -fps
flag allows you to configure the frames-per-second of the simulation. If you set -fps
to 60
, there will be sixty ticks of the game each second.
$ conways-gol -fps 60
conways-gol
was developed by Kyle Banks.
conways-gol
is available under the MIT license.