
A rather simple one is called a "glider":Īs you can see, this thing actually moves in a straight line by one unit on the X and Y axis every 5 generations. There's some cell structures that are worth mentioning. (Because of the size of the canvas and the non-responsive nature of the example, I recommend running it in 0.5 scale) addEventListener ( ' click ', () => )Įnter fullscreen mode Exit fullscreen modeĪnd here's a codepen where you can play around with it: I will create the field as a nested array of 100 by 100 boolean variables:ĭocument. When you connect those sides, the shape will actually look like a donut. Whatever leaves either side will reenter on the opposite side. When the field is shaped like a donut, it behaves like this: There's two possibilities: Either we consider the border as always dead (they are neighbors, but the rules are never applied to them) or the world is actually formed like a donut. Meaning: If the game sets cell 1 as "alive" that was dead before and starts applying the rules to its immediate neighbor cell 2, it should not consider the new state of cell 1 (alive) but the old one (dead) for the calculation of cell 2.īut this begs a question: What does it do at the border of the field? One thing is important, though: The next generation needs to be calculated all at once. In the following picture, we can see how it could look like if a cell is being born: The filled cell in the middle is alive in this generation, but dies the next generation. Here we can see what happens if less than 2 neighboring cells are alive. All other cells are the center cell's neighbors.

We're going to see how the rules work by applying them to the center cell. (These rules allow for some pretty complex structures, but we'll come to that later!) If it has exactly 3 alive neighbors, it will become alive in the next generation, otherwise it stays dead.If a cell was dead in the current generation:.If it has less than 2 (loneliness) or more than 3 (overpopulation) alive neighbors, it dies in the next generation, otherwise it stays alive.If a cell was alive in the current generation:.To determine the next generation, the game looks at each cells neighbors and applies a set of rules: This step is then repeated until the user interrupts.

In each game tick, the game determines which cells are alive and which ones are dead in the next generation. Alive cells can be either set by the user or sprinkled in randomly. You can think of the Game of Life as a sandbox. It's a 2-dimensional field with X and Y coordinates, where each integer coordinate represents a cell that can be either alive or dead, depending on some rules.īut, since it's a game, how is it played? Conway developed the "Game of Life" in 1970 as an applied example of abstract computers.
