Git Product home page Git Product logo

game_of_life's Introduction

Game of Life

This is Conway's Game of Life, a classic computer science exercise, written in Ruby. The game runs in the command-line interface.

More about the game: Wikipedia: Conway's Game of Life

The game was a weekend project after completing week 2 of The Iron Yard Academy's (TIY) Ruby on Rails track in Durham, NC.

Project Requirements*

This is a simulation which is played on a grid. You set up the initial state of the grid and then watch it evolve over generations.

Your initial state is a set of cells that are alive. For each passing generation, the following happens:

  • Any live cell with fewer than two live neighbors dies, as if caused by under-population.
  • Any live cell with two or three live neighbors lives on to the next generation.
  • Any live cell with more than three live neighbors dies, as if by overcrowding.
  • Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

While this game is normally played on an infinite grid, you do not have to necessarily match that model. You could play on a fixed grid (everything outside the grid is dead) or a toroidal grid (each side loops around to the opposite side.)

After you calculate each generation, you should print it out to the screen.

You should ask the user to hit enter to go to the next generation, or you could have it keep printing them one after another, with a second wait in between them -- your choice.

* Requirements written by TIY instructor

Run

To run the game from your terminal, enter the following:

ruby lib/game_of_life.rb

Lessons Applied / Learned

This game was an exercise in bringing together object oriented programming concepts before our class jumped into Ruby on Rails.

While the rules of the game were set, I had to make some decisions about how to set up the grid and handle live cells / dead cells. I chose to keep the live cells for the present generation and prior generation in an array of arrays. The grid is infinite and the size is based on the position of the live cells.

Ideas for Improvement

I would love to do the following when I have some time:

  • Revisit my code and refactor it; this code was written after just two weeks at The Iron Yard
  • Instead of having this run in the terminal, run the game in the browser
  • Add the ability for a player to select a pattern (i.e. 'glider' or 'beacon') and a starting point and have the game automatically generate the pattern automatically

game_of_life's People

Contributors

kheang avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.