

Var result = tick ( present, future ) present = result future = result Step calls tick, and then does something very strange with the return value: The step function has been provided for you in game.js,īut I want us to look at it for a moment. The game must evolve, visually, step by step. Step is wired up, but the others aren't yet. You need to implement all five of these actions for the game. The starting point provides a control panel with five buttons: You might want to add some console.logs to get a sense of what's happening. Until you write paint, it won't be immediately obvious what's going on. Right now, we always toggle the state of the cell at (0,0). You'll need to fix toggleCellFromEvent to figure out which actual cell was tapped and toggle thatĬell. On the page, and listens for mousedown events.
#Game of life starting patterns code#
We've already provided you with some code that creates a of the appropriate size, puts it ThereĪre no tests for this, because the tests would end up being fairly opaque. Game.js contains logic to manipulate the view-that is, the HTML elements on the page. Like randomizing and clearing the board in terms of different rules. In particular, we might describe operations This pattern abstracts away the rules from the thing that applies the rules, making the tickįunction more generally useful than it would otherwise be.

For instance, why not do this?įunction tick ( present, future, rules = conway ) Board modelįor this workshop, we're going to store the board in a 1D typed array. The rules are applied repeatedly to create further generations (one new generation per tick). The discrete moment at which all the births and deaths actually occur is often called a tick. The first generation is created by applying the above rules simultaneously to every cell in the seed - in other words, each generation is a pure function of the preceding one. The initial pattern constitutes the seed of the system. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.Any live cell with more than three live neighbors dies, as if by overcrowding.Any live cell with fewer than two live neighbors dies, as if caused by under-population.Any live cell with two or three live neighbors lives on to the next generation.For each iteration of the board state, the destiny of each cell is determined by these four rules: The game of life is played on a 2D board (easily modeled as an array), where each cell has two possible states: living or dead. Here is an example video showing many of the complex patterns that the Game of Life can produce. In fact, the Game of Life is a universal Turing machine, capable of modeling any algorithmic calculation. The intent and power of the game is not in realistically simulating life, but rather in serving as a simple system that produces complex behavior. It was created by John Horton Conway in 1970, in an effort to simplify a concept by the mathematician John von Neumann in the 1940s. What is the Game of Life?Ĭonway's Game of Life is a set of rules governing the destruction, persistence, or propagation of neighboring cells in a grid - a pseudo-simulation of life. Along the way, we'll continue learning and practicing functional programming, DOM manipulation, and more. We are going to program a JavaScript version of the Game of Life. Using Event.target to handle events via bubbling.

