Assignment 7 Solution

$30.00

Category:

Description

 

Introduction

 

The Game of Life, invented by John. H. Conway, is supposed to model the genetic laws for birth, survival, and death. (See Scientific American, October, 1970, p.p. 120). This game can be played on a board that consists of say 25 squares in the horizontal and vertical directions (so a total of 625 squares). Each square can be empty, or it can contain an X indicating the presence of an organism. Each square has eight neighbors. The color shading shown in the following segment of the board marks the neighbors of the organism named X*:

 

 

 

 

The next generation of organisms is determined according to the following criteria:

 

  1. Birth — an organism will be born in each empty location that has exactly three neighbors;
  2. Death — an organism with four or more organisms as neighbors will die from overcrowding. An organism with fewer than two neighbors will die from loneliness;
  3. Survival — an organism with two or three neighbors will survive to the next generation. Possible generations 2 and 3 for the sample can be found on the next page.

 

It is import to understand that all births, death, and survivals from the current generation to the next occur simultaneously.

 

 

 

 

It is also worth of mentioning that on the board, the top-most row is considered as the neighbor of the bottom-most row (vice versa) and the left-most column is considered as the neighbor of the right-most column (vice versa). In other words, you may think of the game board as wrapping on the surface of a ball.

 

 

 

 

 

 

Program details

 

In this assignment, you are asked to implement the game of life as described above. When it runs, it gets the probability of initial organisms (defaults to 10%, i.e. 10% organisms, 90% empty), height of the board (defaults to 30), and width of the board (defaults to 30) from command line:

 

  • gameoflife [organism probability] [height width]

 

E.g.

 

  • gameoflife ß 10% organisms, 30 by 30 board

 

  • gameoflife 20 ß 20% organisms, 30 by 30 board

 

  • gameoflife 24 40 ß 10% organisms, 24 by 40 board

 

  • gameoflife 15 40 35 ß 15% organisms, 40 by 35 board

 

 

  1. Generate the initial configuration of organisms by random. Calculate and display the organism game board for as many generations as the user wishes (i.e. until the user terminates the game by pressing Ctrl-C).

 

The following is a screen shot of the program:

 

 

 

  1. In your program, each source file (.c file) should contain one and only one function. There should be at least three such source code files. Use appropriate header files (.h files) to declare your functions/variables.Provide a makefile for your program.

 

Programming hints

 

  • Before you display the each generation of organisms, call system(“clear”) to clear the command line window.
  • Every time after you display a generation of organisms, call fflush(stdout) to flush the standard output stream.
  • Sleep for a short amount of time (e.g. 200 microseconds) between two generations by calling usleep(200000). (You need to include h to call this function.)

 

What to submit?

 

Create a tarball file by the name of cs3335_a7_yourlastname.tar that includes

 

  • All completed .c files
  • All completed .h files
  • A makefile

 

Submit the tarball file through BlazeVIEW by the due time.

 


error: Content is protected !!