Giter Site home page Giter Site logo

gameoflife's Introduction

Game of Life

The Game of Life takes place on a two-dimensional, finite, and 2D square grid of cells. Each Cell is in one of two possible states: alive or dead.
Once the grid is initialized, the game progresses in discrete steps called ticks.
At each tick the existing snapshot of the grid is used for each cell to interact with its neighbors based on four basic rules to determine the next state of the grid.
The state of the grid is a representation of the dead and alive cells in a grid of a fixed size.
The following rules are applied for the Grid to move towards a new state:

  1. Any live cell with fewer than two live neighbors dies.
  2. Any live cell with two or three live neighbors lives.
  3. Any live cell with more than three live neighbors dies.
  4. Any dead cell with exactly three live neighbors becomes alive.

Requirements

  • A cell shall be in two possible states: dead or alive
  • The grid shall be of any size that is composed of a square arrangement of cells in 2D, e.g. 10x10, 50x50 etc. Therefore, each cell shall be accessible by a unique (x, y) coordinate.
  • The states of the cells in the grid shall be initialized uniformly at the beginning, i.e. number of alive cells should be roughly equal to the number of dead cells.
  • Neighbors of a cell are defined as the ones, which are in the immediate vicinity that surround the cell (including the diagonals). E.g. any cell inside the grid has 8 neighbors, whereas cells in the borders have 5 and cells in the corners have 3 neighbors. A cell is not its own neighbor.
  • At each tick, the state of the grid shall be updated according to the four neighborhood-based rules above. These rules shall be applied to all cells simultaneously, i.e. the order of cells to which the rules are applied should not affect the outcome.
  • The state of the grid shall be represented as a string, where dead cells are represented with a “-” (dash) and alive cells are represented with a “*” (star) character. When printed, this string should be displayed in N lines (rows of the grid), each consisting of N characters (columns of the grid), where NxN is the size of the grid.
  • You shall throw a NegativeCoordinateException when a cell receives negative coordinates, a CellCoordinateOutOfBoundariesException when the Grid contains cell outside its limits, and a CustomLifeException for all other error cases.

gameoflife's People

Contributors

dfucci 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.