The Game of Life is a cellular automaton devised by the British mathematician John Horton Conway.
The Game of Life is played on a two-dimensional rectangular grid of cells. Each cell can be either alive or dead. The status of each cell changes each turn of the game - also called a generation - depending on the statuses of that cell's eight neighbors.
You can find out more about the Game of Life watching this awesome video or reading this Wikipedia entry.
See it in action on Youtube by clicking here.
This is a simple implementation of Conway's Game of Life written in the Ruby programming language. It is a part of my apprenticeship at 8th Light, Inc.
This project further caught my interest while reading the book Understanding the Four Rules of Simple Design by Corey Haines.
To know more about my development process and what I learned, visit my blog.
The rules of the game are explained clearly in it's Wikipedia entry. The relevent portion is quoted here:
The universe of the Game of Life is an infinite two-dimensional grid of square cells, each of which is in one of two possible states, alive or dead. Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:
- Any live cell with fewer than two live neighbours dies, as if caused by under-population.
- 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 overcrowding.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
The initial pattern is the first generation. The second generation evolves from applying the rules simultaneously to every cell on the game board, i.e. births and deaths happen simultaneously. Afterwards, the rules are iteratively applied to create future generations.
To get started you'll first want to install the sdl2 library
if its not already installed on your computer. If it's already installed, you can skip this step.
Run the following using terminal:
brew install sdl2
Note: You need Homebrew package manager to use the above mentioned command. To install Homebrew, paste the following in Terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then install the required Ruby gems which you can do easily using bundler:
- Install Bundler by using the following command in the terminal.
gem install bundler
- Move over to the project directory using
cd
command and run the following:
bundle install
Once the gems have been installed successfully, you can play the Game of Life by passing the game.rb file to the Ruby interpreter:
- Use the
cd
command to move over to thelib
folder. - Then use the following command in terminal to run the game:
ruby game.rb
Tests are run on the command line using RSpec.