- Home
- Game of Life
- Bubbles Game
- Glass Renderer
- Sentry AI Demo
- Font/Graphics
|
Conway's Game of Life
Description:
A small (and finite) implementation of Conway's Game of Life, the most well-known cellular automaton. Of particular note in this implementation is the manner in which the cells are stored-- both a list of live cells and an array of the state of every cell are kept. While redundant (and clearly a poor choice if the program were to be expanded beyond a small scale), using an array allows a much faster check of whether a cell has neighboring live cells (to be precise, it is constant time, whereas the same check through the list would be O(n)). This program uses SDL.
Conway's Game of Life consists of a board (infinite by definition, although not in this program) comprised of a grid of cells which can exist in one of two states: on (or "alive") or off (or "dead"). The game progresses in a series of discrete time intervals, called "generations." In each of these stages, the cells are changed according to a set of rules regarding their neighbors (the eight surrounding cells). A dead cell with exactly three neighbors becomes alive (it is "born"), and a live cell with anything but two or three neighbors dies.

Example 1
In these examples, live cells are shown in grey and dead cells are shown in white. Cell a in Example 1 has three neighbors, so it will be born in the next generation. Cell b has two neighbors, so it will survive. The two unmarked live cells each have only one neighbor (b), so they will die. These changes are shown below.

Example 2
The command line option for using alternate rules is "life x/y" where x are the survival rules and y are the birth rules. Note that 0 is not an acceptable rule for birth in this program.
Sample rules from http://en.wikipedia.org/wiki/Conway's_Game_of_Life#Variations_on_Life:
life /3
(stable) almost everything is a spark
life 5678/35678
(chaotic) diamonds, catastrophes
life /2
(exploding) "Seeds" phoenix, minimal
life /234
(exploding) phoenix, lacey patterns
life 12345/3
(exploding) maze-like designs
life 125/36
(chaotic) Life-like 2x2 block rule
life 1357/1357
(exploding) everything is a replicator
life 1358/357
(chaotic) a balanced amoeba rule
life 23/3
(chaotic) "Conway's Life"
life 23/36
(chaotic) "HighLife" (has replicator)
life 235678/3678
(stable) ink blot, quick drying
life 235678/378
(exploding) coagulations in chaos
life 238/357
(chaotic) broken life
life 245/368
(stable) death plus puffers and ships
life 34/34
(exploding) "34 Life"
life 34678/3678
(exploding) "Day & Night"
life 45678/3
(exploding) slow coral growth
life 5/346
(stable) "Long life"
Controls:
Left-click: Turn a cell on.
Right-click: Turn a cell off.
Space bar: Run the game at full speed.
S: Step through the stages (and stop running).
R: Randomize board.
C: Clear board (kill all cells).
Code files:
cell.cpp
Cell class, contains data and methods for live cells, acts as a singly-linked list
cell.h
Cell class header
event.cpp
Event class, contains data and methods for birth/death events, acts as a singly-linked list
event.h
Event class header
font.cpp
Font class, contains data and methods for font objects
font.h
Font class header
gfx.cpp
Graphics primitives library (points, lines, circles, etc.)
life.cpp
Main program
rules.cpp
Rules class, contains data and methods for game rules, acts as a singly-linked list
rules.h
Rules class header
All example content by David Pittman. HTML by J. Kyle Pittman and David Pittman.
|