Coder Social home page Coder Social logo

conwaygameoflife's Introduction

Conway's Game Of Life

Brief & Details

Task:

Implement Conway's Game of Life using TDD, to satisfy tests based on the scenarios listed below.

Links:

Assumptions made:

It's assumed that a new instance of the GameOfLife class is made by passing in an array of arrays, containing 1's or 0's to indicate life and death:

let board = [
  [0,0,0],
  [1,1,1],
  [0,0,0]
]
let game = GameOfLife.new(board);

There are some checks to make sure the input is sensible, but it's assumed the values inside are either 0 or 1.

Not infinite : My solution isn't infinite as the brief describes, but can take in starting states of different sizes.

The edges of the board are solid boundaries: The grid doesn't wrap around (similar to a game of Snake, or Pac-Man). This could probably be added by using a modulo to calculate coordinates of neighbours on the other side of the board.

This change would allow the simulation to sustain itself much longer, as the boundaries reduce the number of possible neighbours and inhibit life.

Cloning this project

Clone this repository and run npm install.

Tests:

Mocha is used to run tests for different scenarios (see below). Use the command npm run test to run all the tests.

  • npm run scenario : runs just integration tests from the brief (test/scenarios.js)
  • npm run unit : runs just unit tests for the GameOfLife class (test/unit-tests.js)

The above should work for using the local mocha files, but if there are issues with mocha install it globally using npm i --global mocha and then run mocha in the project's root.

Scenarios

Use these for test driven development

Scenario 0 No interactions

Given a game of life

When there are no live cells

Then on the next step there are still no live cells

Scenario 1: Underpopulation

Given a game of life

When a live cell has fewer than two neighbours

Then this cell dies

Scenario 2: Overcrowding

Given a game of life

When a live cell has more than three neighbours

Then this cell dies

Scenario 3: Survival

Given a game of life

When a live cell has two or three neighbours

Then this cell stays alive

Scenario 4: Creation of Life

Given a game of life

When an empty position has exactly three neighbouring cells

Then a cell is created in this position

When applied these scenarios result in the following:

Scenario 5: Grid with no live cells

Given a game of life with the initial state containing no live cells

When the game evolves one turn

Then the next state also contains no live cells

Scenario 6: Expected game outcome for seeded grid

Given a game of life with the initial state...

+---+---+---+
| O | O | O |
| X | X | X |
| O | O | O |
+---+---+---+

When the game evolves one turn

Then the next state is...

+---+---+---+
| O | X | O |
| O | X | O |
| O | X | O |
+---+---+---+

When the game evolves another turn

Then the next state is...

+---+---+---+
| O | O | O |
| X | X | X |
| O | O | O |
+---+---+---+

conwaygameoflife's People

Contributors

dependabot[bot] avatar sarahfrench 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.