Skip to content

Conway´s Game of Life in Ruby refactored to different files containing each class

Notifications You must be signed in to change notification settings

candanedo/GameOfLifePOO

Repository files navigation

GameOfLife

Conway´s Game of Life in Ruby

The Game of Life is not your typical computer game. It is a 'cellular automaton', and was invented by Cambridge mathematician John Conway.

This game became widely known when it was mentioned in an article published by Scientific American in 1970. It consists of a collection of cells which, based on a few mathematical rules, can live, die or multiply. Depending on the initial conditions, the cells form various patterns throughout the course of the game.

The Rules

For a space that is 'populated': Each cell with one or no neighbors dies, as if by solitude. Each cell with four or more neighbors dies, as if by overpopulation. Each cell with two or three neighbors survives. For a space that is 'empty' or 'unpopulated' Each cell with three neighbors becomes populated.

Development

So, for this task we are going to create a terminal interface program that will allow you to observe the behavior of the cells involve on the game; living and dying according to the rules. To see this go ahead and download the following repository https://github.com/candanedo/GameOfLifePOO

Once you have cloned it, you´ll see a directory named “lib”, which contains a file GameOfLife.rb go ahead and open the file on the terminal with the command ruby, and just like that you can determine the size of the grid and also set the initial conditions of the game, basically how many cells are going to be alive at the beginning of the game and also the position of each one.

First of all the game will ask you to establish the size of the grid, the when you determine that, the program will display the grid that you defined (for the terminal interface is recommended to use a range between 10-30 that way it will be more visual). Keep in mind that the grid size must be greater than 0 otherwise the program will ask you again for the size until the input value is numeric and greater than 0.

After the grid is defined, the program will ask for the initial conditions of game, this means that the user must type the coordinates for each living cell, when the game begins it will consider those living cell as the initial conditions for live, and the program will determine which cell keep living and which ones will die.

The program allows the user to enter as many living cell as he/she wants, after each coordinates given, the program validates if you want to keep adding cells if you continue to type anything different than 1, when you type 1 the game begins.

Ruby Gem.

The Gem is contained on the same repository, the latest version is the one that includes all validations and latest features so use that one (version 1.0.4). This version will need to be initialize on interactive Ruby.

You will also find another version 1.0.5, this version will not require to initialize the game, it only needs to be require and that is it.

If you want to take a look to all the repositories created during the duration of this challenge; such as the RubyKoans, the first versions of the deliverables and more you can access to https://github.com/candanedo?tab=repositories

Conclusions

For this challenge we were able to lean the syntax of Ruby language, some of the things that I was able to notice is that the language is very powerful and yet very simple to learn and implement.

Another important thing that I realize is that the Ruby community is very active and very supportive.

About

Conway´s Game of Life in Ruby refactored to different files containing each class

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages