Home CPSC 305

Conway's Game of Life

Due: February 15


To gain experience writing C programs, and working with binary data by writing a version of Conway's Game of Life.

Conway's Game of Life

This game is a type of cellular automata and simulates a simplified grid world.

For our purposes, the grid will consist of 40 rows and 80 columns. Each spot in the grid can either be empty, or have a live cell in it. The simulation consists of successive generations. At each generation, the following rules are applied:

  1. Any live cell with fewer than two neighbors is dead in the next generation.
  2. Any live cell with more than three neighbors is dead in the next generation.
  3. Any live cell with two or three neighbors survives.
  4. Any empty cell with exactly three neighbors becomes live in the next generation.
  5. Any empty cell with a number of neighbors not equal to three remains empty.

Here "neighbors" refers to live cells that are to the left, right, top, bottom or diagonal of the cell. A cell can have from zero to eight neighbors.

Note that the neighbors count cells that are live in this generation, regardless of whether or not they will be live the next.

Program Details

Your program should take two parameters. First is the name of the input file. This file contains a bit for each cell in the grid. There are $40 \times 80 = 3200$ bits which is equal to $3200 \div 8 = 400$ bytes.

If a bit is 1, that means the corresponding cell is alive. If it is 0, it means that cell is dead.

The first byte stores the first eight cells from the first row of the grid world. The most significant bit in the byte comes first, so location (0, 0) is given by the most significant bit of the first byte in the file.

To see if a given cell is alive, you need to first find which of the 400 bytes it is in, and then test the individual bit in that byte.

The second parameter is a positive integer, $N$, which indicates the number of generations to simulate.

Your program should simulate $N$ generations, according to the rules above, and output the final state of the grid to the screen. Any dead cells should be output as spaces, and live cells should be output with the 'O' character.

Test Files

You can test your program with the following input files.

Test FilesOutput After 100 Generations



When your program works, email the source code to ifinlay@umw.edu.

Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.