Game of Life Lab

Programming Project 4

CPE 101 Spring 2011

Turner


Chapter 8, Programming Project 15 in the 5th Edition.  This problem is not reprinted in the 6th Edition of the text.  The problem is to write a program to implement the "Game of Life" 


Hint:    Do a little research with the concepts before beginning work, the Wikipedia page is a good start.  


Hint:  This problem involves more design than previous projects - working out an overall structure of the program that works well for writing the program BEFORE writing code.  It involves such activities as developing good variable names, making good choices for the tasks to separate into functions, your decisions on a simple way to display the results to the user, thinking up some good test cases to see if it all works well, deciding on key "probe" points where you might insert printf statements into the code to help you to understand how the program progresses as you write and test it,  things like that.  Review the book chapters and your notes on modularity and other facets of program design / problem solving.  

Basic rules to follow in the Game of Life:




The universe of the Game of Life is an infinite two-dimensional orthogonal
grid of square cells, each of which is in one of two possible states, live
or dead. Every cell interacts with its eight neighbours, which are the cells
that are directly horizontally, vertically, or diagonally adjacent. At
each step in time, the following transitions occur:

   1. Any live cell with fewer than two live neighbours dies, as if by
loneliness.
   2. Any live cell with more than three live neighbours dies, as if by
overcrowding.
   3. Any live cell with two or three live neighbours lives, unchanged,
to the next generation.
   4. Any dead cell with exactly three live neighbours comes to life.

The initial pattern constitutes the 'seed' of the system. The first generation
is created by applying the above rules simultaneously to every cell in the
seed tion of the one before.) The rules continue to be applied repeatedly
to create further generations.

____________________________________

Write your program  to play the game on a board that consists of 25 squares in the hirizontal and vertical directions (a total of 625 squares). Each square can be empty, or it can contain an X indicating the presence of an organizm.  Each square (except for the border squares) has eight neighbors.  

Follow the rules of the Game of Life to take an initial configuration of organisms as input data.  Display the original game array, calculate the next generation of organisms in a new array, copy the new array into the original game array, and repeat the cycle for as many generations as you wish.  Hint: Asume that the borders of the game array are infertile regions where organisms can nether survive nor be born; you will not have to process the border squares.  

FIRST, due on Monday, 23 May, is an overall DESIGN for the program.  See Chapter 3 and Chapter 6 in your textbook.  In particular, I want you to produce a document  with a very simple overview pargraph description at the top, the basic algorithm you will use, then describe the main program (as a skeleton with variables named and declared, appropriate functions named and called, a program "skeleton" with comments and the high level constructs completed.   Each function must be described and a skeleton presented (as it would be declared in your program, comments to describe what it will do).  The overall program should be described with a diagram (something like that on page 125 of your text) to show the algorithm refinement into the functional structure.  This document should be completed BEFORE you write code.  You may change your mind and your ideas after you submit this document, but it should be completed before you write the program.