Please enable JavaScript to use CodeHS

The Game of Life

In this project, students create a Conway's Game of Life simulator using 2D vectors.

Hard

5 Hours

High School

Project Description

Background

Conway’s Game of Life is a simulation that was originally created in 1970 by John Conway. The idea behind it is to simulate cell automation. It is considered a zero player game in the sense that once the initial state is set, the simulation continues on automatically.

Rules

The game is played on a square board. (We will use a default value of 15 by 15, but you can update this.) Each position on the board represents either a living cell (X) or a dead cell (O). The initial board will have some living and some dead cells. In each round, the status of each cell gets updated based on the following rules:

If the cell is alive:

  • It stays alive if 2 or 3 of its neighbors are also alive
  • Otherwise it dies

If the cell is dead:

  • It becomes alive if exactly 3 of its neighbors are alive
  • Otherwise it remains dead

A neighbor is considered any cell touching the current cell horizontally, vertically, or diagonally. A cell in the middle will have 8 neighbors. Cells on the edges and corners will have fewer.

Your Task

You will start by using a 2D character vector to create the original board and randomly set the cells as dead or alive. You will then add in the simulation that executes the rules of the game!

Project Demo

Explore this program before assigning it!

Project Overview

Here is an outline of the project activities: