Skip to content

michelmansour/GameOfLife

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

An implementation of Conway's Game of Life in Ruby

From the command line:

gol_app.rb -d N,M -a X1,Y1,X2,Y2,... -b <standard|torus>
       -d N,M Width and height of the world
       -a X1,Y1,... Specifies which cells are alive
                    to start
       -b  Border rule: standard (default) or torus
     -h, --help Show the usage message

Or from within Ruby (or irb):

Create an instance of the GameOfLife class:

gol = GameOfLife.new(5, 5, [[1, 2], [2, 2], [3, 2]], :torus)

The first parameter is the width of the world; the second is the height. The third parameter is an array of coordinates whose cells are initially alive. The last parameter is the rule to apply at the border for neighbor cells. :standard treats the border as dead cells, while :torus wraps around the board.

gol.print_world
 - - - - -
 - - * - -
 - - * - -
 - - * - -
 - - - - -

Living cells are represented by *, dead ones by -. These are optional parameters to print_world.

Advance a single generation:

gol.run_generation
gol.print_world
- - - - -
- - - - -
- * * * -
- - - - -
- - - - -

Run the simulation:

gol.run

This will print out the state of the world after each generation, pausing a moment between iterations.

Initial Configurations of Interest

Beacon

$ gol_app.rb -d 6,6 -a 1,1,2,1,1,2,3,4,4,3,4,4

- - - - - - 
- * * - - - 
- * - - - - 
- - - - * - 
- - - * * - 
- - - - - -

Pulsar

$ gol_app.rb -d 15,15 -a 3,1,4,1,5,1,9,1,10,1,11,1,1,3,1,4,1,5,6,3,6,4,6,5,8,3,8,4,8,5,13,3,13,4,13,5,3,6,4,6,5,6,9,6,10,6,11,6,3,8,4,8,5,8,9,8,10,8,11,8,1,9,1,10,1,11,6,9,6,10,6,11,8,9,8,10,8,11,13,9,13,10,13,11,3,13,4,13,5,13,9,13,10,13,11,13

- - - - - - - - - - - - - - - 
- - - * * * - - - * * * - - - 
- - - - - - - - - - - - - - - 
- * - - - - * - * - - - - * - 
- * - - - - * - * - - - - * - 
- * - - - - * - * - - - - * - 
- - - * * * - - - * * * - - - 
- - - - - - - - - - - - - - - 
- - - * * * - - - * * * - - - 
- * - - - - * - * - - - - * - 
- * - - - - * - * - - - - * - 
- * - - - - * - * - - - - * - 
- - - - - - - - - - - - - - - 
- - - * * * - - - * * * - - - 
- - - - - - - - - - - - - - -

Glider

$ gol_app.rb -d 20,10 -a 1,1,2,2,3,2,1,3,2,3 -b torus

- - - - - - - - - - - - - - - - - - - - 
- * - - - - - - - - - - - - - - - - - - 
- - * * - - - - - - - - - - - - - - - - 
- * * - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - -

Gosper Glider Gun

$ gol_app.rb -d 38,30 -a 1,5,2,5,1,6,2,6,35,3,36,3,35,4,36,4,11,5,11,6,11,7,12,4,12,8,13,3,13,9,14,3,14,9,15,6,16,4,16,8,17,5,17,6,17,7,18,6,21,3,21,4,21,5,22,3,22,4,22,5,23,2,23,6,25,1,25,2,25,6,25,7

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - * - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - * - * - - - - - - - - - - - -
- - - - - - - - - - - - - * * - - - - - - * * - - - - - - - - - - - - * * - 
- - - - - - - - - - - - * - - - * - - - - * * - - - - - - - - - - - - * * - 
- * * - - - - - - - - * - - - - - * - - - * * - - - - - - - - - - - - - - - 
- * * - - - - - - - - * - - - * - * * - - - - * - * - - - - - - - - - - - - 
- - - - - - - - - - - * - - - - - * - - - - - - - * - - - - - - - - - - - - 
- - - - - - - - - - - - * - - - * - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - * * - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

About

Conway's Game of Life

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages