You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Conway's Game of Life is a cellular automaton devised by the British mathematician
John Horton Conway in 1970.[1] It is a zero-player game, meaning that its evolution
is determined by its initial state, requiring no further input. One interacts with
the Game of Life by creating an initial configuration and observing how it evolves.
It is Turing complete and can simulate a universal constructor or any other Turing
machine. [1]
This repository contains a fully functional Javascript powered application as well
as an unfinished Python file. This entire document pretains to the JS creation. I
thought it could be favorable to include both versions in the repository.
If you are interested in using the application that I have created, it can be found
here ____. The instructions are below.
Instructions:
This is a zero player game. The only control given are the initial parameters.
The game will automatically load with a randomly seeded board. The rules that
the game follows to decide how the board will behave, are as follows:
1. Any live cell with fewer than two live neighbours dies, as if by underpopulation.
2. Any live cell with two or three live neighbours lives on to the next generation.
3. Any live cell with more than three live neighbours dies, as if by overpopulation.
4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
These rules can be distilled into the following:
1. Any live cell with two or three live neighbours survives.
2. Any dead cell with three live neighbours becomes a live cell.
3. All other live cells die in the next generation. Similarly, all other dead cells stay dead.
Controls:
Play: Sets the game into motion.
Pause: Pauses the game.
Clear: Clears the game board.
Seed: Randomly generates a new seed.
Step Forward: Ticks the game forward one generation.
Speed: Chooses the rate at with the generations progress.
Size: selects the size of the game board.
The Assignment
I was tasked with recreating the Game of Life (GOL) in whatever language I saw fit.
So far with my education at lambda I have had experience with, HTML, CSS, Javascript,
mostly in the form of React, and with Python. I elected to complete the task using React,
as that is the language that I am most framiliar with.
My Thought Process
Initial planning lead me to outline several basic components that I would need to create
in order to replicate Conway's GOL. Those components are as follows:
Game board
Box/Cell
Selection Method
Play Method
Logic Operations
Component Design
1. The Game Board
The gameboard is constructed of a react class called Grid. It is
initialized as an array of rows with a nested for loop that creates
an array of columns and uniquly identifies each cell as boxId i_j.
2. The Box/Cell
Each box is passed in from the array as props and is renderd as a div
that contains a unique ID and allows the onclick event, select box.
The select box, triggers both a value of true, and tells the CSS to
either render the box as, white (off state) or green (on state)
3. The Selection Method
Per the design spec the selection method needed to buffer the existing
array and my selection method follows that guidline. The function clones
the array with a helper function (it uses a cool trick that leverages
parse and stringify) and checks to see if they new buffered array has
any changes. Once it determines that the array does have a difference,
it overwrites the original "current" array.
4. The Play Method
The play method also leverages teh double buffer design. It clones the
array and then applies the logical parameteres defined be the rules.
Once complete, the buffered array takes the place of the current array,
and the generation counter increments by 1.
5. The Logic Operations
Each generation of the game is determined by applying a check to every
single cell on the board. That check looks at all of the neighboring
cells (eight per cell) and counts how many cells are alive or dead. If
the cell has the magic number of 3 living cells, it will become alive.
Otherwise the cell dies or remains dead.
_Sources_
[1] https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
[2] https://www.youtube.com/watch?v=PM0_Er3SvFQ