Workshop › Conway's Game of Life › Step 5 of 32

The world in memory

What we are doing

The picture is not the world; the world is data. Each cell is a number, 1 alive and 0 dead, and the grid is a list of rows, each row a list of cells: grid[row][col]. We make an all-dead grid.

```js
let grid // grid[row][col]: 1 alive, 0 dead

const emptyGrid = () => Array.from({ length: ROWS }, () => Array(COLS).fill(0))

function reset() {
  grid = emptyGrid()
}

reset()
draw()
```

What it means

Your turn

  1. Under const TOP = 36, after an empty line, write let grid, emptyGrid and reset as shown.
  2. At the bottom, write reset() above draw(). Press Run.

Skills: Arrays and objects

All steps

  1. The board
  2. Measure the grid
  3. One living cell
  4. A function that draws
  5. The world in memory
  6. Draw every living cell
  7. A random soup
  8. Count the neighbours
  9. Four rules
  10. Draw again and again
  11. Next generation with N
  12. Count the generations
  13. Show the generation
  14. A world without edges
  15. Count the living
  16. A generation every few frames
  17. Let it live
  18. Running or not
  19. One place for the buttons
  20. Space to play, N to step
  21. Clear and shuffle
  22. Where is the pointer?
  23. Which cell?
  24. Click a cell
  25. Paint or erase?
  26. Drag to paint
  27. Patterns from text
  28. The glider gun
  29. Fire the gun
  30. Buttons on the screen
  31. Tap the buttons
  32. Build it yourself: a world at rest