Conway's Game of Life is an early example of a cellular automaton which can be easily simulated on a computer. A cellular automaton consists of a large number of cells, each operating according to some simple local rules. Given a large enough number of cells and an interesting initial configuration, non-trivial emergent behavior can result.
See the Wikipedia article on Life (first link above) and carefully read the "Rules" section and look over some of the examples of cellular automata.
We will use the simplified rules where: a dead cell with exactly 3 neighbors becomes live; and only a live cell with 2 or 3 neighbors survives, all others die.
Note incidentally that this simulation has no relation to the board game "Life".
Write a program that simulates the playing or animation of Conway's Game of Life on a 40-by-40 board, displayed as Xs (live cells) and blank spaces (dead cells). You may make the board size (40) a global variable.
Your files will consist of: lifefunc.h, lifefunc.c, and playlife.c (resp., the header, functions file, and main driver), as well as a Makefile that will generate an executable named playlife (you may use this Makefile; or edit it in case you need to add more flags, or more files).
Your program should be designed to run in two possible modes: interactive and batch.
The mode chosen will be determined by how the program is run:
1) interactive mode: this mode will be triggered when the program is executed with no command line arguments
Initially, the program should set up a completely blank board; it should then ask the user for input:
If the user enters:
2) batch mode: this mode will be triggered if the executable is followed by a data file.
The data file will consist of a sequence of commands (see above) followed by a "p". Lines starting with an "a" or an "r" will be followed by two numbers (representing a cell's location). A typical data file (scene) will most likely consist of just "a" lines (an a followed by two integers), ending with a solo "p" line at the end.
In this batch mode, the program will play the scene continuously.
You may assume that all data files will definitely have a "p" as the last line; and that all scene files are always valid and correct.
For instance: here is an example of a simple glider scene, glider.txt, which creates cells that move across the screen diagonally.
Example usage:
playlife --> Game of Life in interactive mode
playlife glider.txt --> Game of Life in batch mode, using that scene
Note that the sides of the board are fixed sides, and the board does not 'loop around'.