Part 1

The game consists of a board of varying size, where each cell can be either alive or dead at any time step. Then the next time step is calculated according to the three following rules:

  • Any live cell with fewer than two live neighbours dies, as if caused by under-population.
  • Any live cell with two or three live neighbours lives on to the next generation.
  • Any live cell with more than three live neighbours dies, as if by overcrowding.
  • Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

Where a neighbor is any cell that is horizontally, vertically or diagonally adjacent.

The first part of the project is a basic implementation of Life. The initial configuration of the game will be provided in a file, and you should print the configuration of the game at each time step.

The following input files will be provided: Block, beehive, traffic, glider and Methusalah.

The initial configuration specifies the number and position of cells that are initially live. The number of initially live cells is provided in the first line of the file. Then the row/column position of each live cell is provided on a separate line. So for instance the traffic light life form is defined by the file traffic, which contains:

3
2 1
2 2
2 3

In this case three cells are initially alive, with row/column positions as indicated.

To display the life game board graphically you should use the primitive but effective function printf(). At each time step, including the first, print the complete board, the width and height being specified on the command line as described below. Cells outside the game board are to be considered as always dead. Print an X for each live cell and a space for each dead cell. Row 0 is the first row you should print, i.e. the top row. Column 0 is the left column. You should also print a border for the board, with asterisks * at the four corners, hyphens - along the top and bottom, and vertical lines | (pipe symbols) along the left and right vertical borders. Note that the board width and height are excluding the border, so that the total printed width and height including the border will be width+2 and height+2. Two blank lines should be printed between the outputs for each time step. A fixed number of time steps is provided (see below), after which the program should exit, with a blank line followed by the word Finished by itself on a single line. So for instance, given the traffic as initial configuration, width 7 cells and height 5 cells, and three time steps, your program should output as in Fig. 1. The first board printed is the initial configuration, so four configurations are printed in total. It so happens that the traffic configuration is a blinker with a period of two, so the configuration repeats.

Write your program in the file life1.c, and compile it with the command gcc -ansi -Wall life1.c -o life1

The program should take exactly four arguments on the command line, in the order file-name, width, height, generations. The maximum size for the game board will be width 78 cells and height 50 cells. So to run the program on the traffic file as above, the command line would be

./life1 traffic 7 5 3

You may find it convenient to print messages to standard error. It is also useful to be able to control the progress of the game by waiting for keyboard input at each generation. You are recommended to use fgets() for this purpose. However if you do this you should REMOVE the keyboard input source code before submitting your program.

Test the program with the other initial configurations, the block, beehive, glider and methusalah life forms are provided, as described in the game description attached at the back. The block and beehive are still-lifes, life forms that do not change. As described above, traffic is a blinker, repeating itself every second generation.

Figure 1: Program output given the traffic as initial configuration, width 7 cells and height 5 cells, and three time steps.

For the glider and methusalah life forms you will need to use a larger board, say width 70 and height 40. The glider should repeat every four generations, but also shift diagonally down and to the right at every such repeat. methusalah is a simple initial pattern that gives rise to increasingly complex patterns, before eventually stabilising. In Fig. 2 is the configuration of methusalah after 100 generations, with width/height set to 70/40 as suggested.

Part 2

Copy the program life1.c into a new file life2.c, which is to be the program to work on in the second part. It is to be modified the to show the age of live cells. This is done by replacing the X symbol for live cells by a digit from 0 to 9 indicating the number of generations that the cell has survived since it was born. An age greater than 9 is indicated as before by an X. Cells are assigned an age of zero upon creation. To repeat the traffic test from part 1, run the command

./life2 traffic 7 5 3
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.