/GameOfLife

Implementing the Game of Life, a cellular automation formulated by John Conway in React with React Hooks & ES6.

Primary LanguageJavaScript

License: MIT

An interactive tool that simulates a cellular automaton: a set of cells that evolve over time based on a set of rules. It is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input.

Rules of the Game

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, (or populated and unpopulated, respectively). Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent.

  • Any live cell with two or three live neighbours survives.
  • Any dead cell with three live neighbours becomes a live cell.
  • All other live cells die in the next generation. Similarly, all other dead cells stay dead.

Tech

  • HTML
  • CSS
  • ReactJS

Deployed App

Click to go to live game

Getting Started

  1. Install dependencies
npm install
  1. Run the app in development mode
npm start
  1. Open http://localhost:3000 to view it in the browser

Visualizing the "Game of Life"

The main entry point of your application should house the visualization of this cellular automaton. Include necessary components, such as:

  • Grid to display cells.
  • Cell objects or components that, at a minimum, should have:
    • Properties
      • current state: (alive, dead), (black, white)
      • Clickable/Tappable:
        • can be clicked to allow user to setup initial cell configuration
        • should NOT be clickable while simulation is running
      • Behaviors
        • Toggle state functionality: switch between alive & dead either because user manually toggled cell before starting simulation or simulation is running and rules of life caused cell to change state
  • An appropriate data structure to hold a grid of cells that is at least 25x25. Go as big as you want.
  • Text to display current generation # being displayed
    • Utilize a timeout function to build the next generation of cells & update the display at the chosen time interval
  • Button(s) that start & stop the animation
  • Button to clear the grid

Write an algorithm that:

  • Implements the following basic steps:
    • For each cell in the current generation's grid:
      1. Examine state of all eight neighbors (it's up to you whether you want cells to wrap around the grid and consider cells on the other side or not)
      2. Apply rules of life to determine if this cell will change states
      3. When main loop completes:
        1. Swap current and next grids
        2. Repeat until simulation stopped
  • Breaks down above steps into appropriate sub-tasks implemented with helper functions to improve readability
  • Uses double buffering to update grid with next generation.
  • Does something well-documented with the edge of the grid. (e.g. wrap around to the far side--most fun!--or assumes all edge cells are permanently dead.)