Code Monkey home page Code Monkey logo

gameoflife's Introduction

Conway's Game of Life

Conway's Game of Life, also known as the Game of Life or simply Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970. It is the best-known example of a cellular automaton. The "game" is actually a zero-player game, meaning that its evolution is determined by its initial state, needing no input from human players. One interacts with the Game of Life by creating an initial configuration and observing how it evolves

Rules

The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, live or dead. Every cell interacts with its eight neighbours, which are the cells that are directly horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

    1. Any live cell with fewer than two live neighbours dies, as if by needs caused by underpopulation.
    1. Any live cell with more than three live neighbours dies, as if by overcrowding.
    1. Any live cell with two or three live neighbours lives, unchanged, to the next generation.
    1. Any dead cell with exactly three live neighbours cells will come to life.

The initial pattern constitutes the 'seed' of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed โ€” births and deaths happen simultaneously, and the discrete moment at which this happens is sometimes called a tick. (In other words, each generation is a pure function of the one before.) The rules continue to be applied repeatedly to create further generations.

Design

The Structure of the Solution is Divided like this.

Cell (Alive or Dead) Axis -> groups of Cells (Rows or Columns) Grid -> combination of 2 Axis

A Cell implements a State, either Dead or Alive. Based on its state various calculations are performed. A Cell is responsible for its own life. It keeps a tab of all its neighbours via Observers and accordingly modifies its noOfAliveNeighbours property which is then used to decide the fate of the cell through the next generation.

An Axis merely holds a collection of Cells.

The Grid holds as many Axes as necessary, in our case primarily 2. The Grid instantiates an empty playing field based on the input recieved. Cells are made to observe their neighbours so that they can keep track of their own life and death based on their neighbours. A stepUp operation advances the game to the Next Stage.

Unit Tests

Unit Tests have been written for the two main functional units - Cell and Grid. These can be run from the command line via ant.

ant test -> will run the junit tests.

ant run -> will run the Project

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.