Wednesday, March 31st at NOON
You will be coding the Game of Life again! But there are some twists this time. Life contains a two-dimensional grid of cells. A cell can only be in one of two states: alive or dead. There are two kinds of cells: ConwayCells and FredkinCells. Once the grid is manually populated with live and/or dead cells, the grid represents the 0th generation of Life. After that, everything is automatic, and Life evolves from the 1st to the Nth generation. A generation is simply the state of the grid (i.e. the layout of the live and dead cells). Live ConwayCells are denoted with an asterisk, "*", and dead cells are denoted with a period, "." (when printing the board please insert spaces between cells). A ConwayCell has 8 neighbors, if it's an interior cell, 5 neighbors, if it's an edge cell, and 3 neighbors, if it's a corner cell. The example below is of 1 ConwayCell that is alive surrounded by 8 ConwayCells that are dead:
ConwayCells do not have the notion of age, FredkinCells do. A FredkinCells' age is initially zero and only increments by one if the cell is alive and stays alive. Live FredkinCells are denoted with their age, if their age is less than 10, otherwise denoted with a plus, "+", and dead cells are denoted with a minus, "-". A FredkinCell has 4 neighbors, if it's an interior cell, 3 neighbors, if it's an edge cell, and 2 neighbors, if it's a corner cell. The example below is of 1 FredkinCell that is alive and of age 5 surrounded by 4 FredkinCells that are dead:
. . .
. * .
. . .
The rules for going from one generation to the next for ConwayCells are:
- 5 -
CLARIFICATION on the Cell class: It should NOT be a derived class of AbstractCell. Life will have to contain a grid of cells to implement the game of life. Probably the easiest way to contain many cells is with a Standard Template Library (STL) container such as vector. Because it is not possible to place AbstractCells themselves into a vector, and it is a bad idea to place AbstractCell* (pointers to AbstractCell) into a vector, the Cell class will solve these problems. The reason it is bad for pointers to AbstractCell to be in a vector is because to assign one vector to another, one would need assignment operators and copy constructors in the AbstractCell class - but it is abstract. So, the solution is to have a wrapper class - class Cell. It's like a smart pointer if you want to read about them. But all you need to know is that you pass an already allocated pointer to either a FredkinCell or ConwayCell (aka a pointer to an AbstractCell) to the constructor of the Cell class. It'll wrap objects of those 2 derived classes, and manage their memory - aka delete them in its destructor. Then it can have an assignment operator and a copy constructor so you can just assign one vector to another in your Life class. Also, it will need wrapper functions for your (virtual) methods defined in AbstractCell. For example, if you defined a virtual function evolve in AbstractCell, you would need a function in your Cell class called evolve so that in the Life class you can just call Cell->evolve, which will simply be a wrapper and polymorphically call the appropriate evolve function of your classes derived from AbstractCell. So this is what is intended by the Cell class - Good luck!In a main program, you will read in initial board states from an input file and iterate through several generations of the game of life. You will also create a Makefile to compile all your C++ files.
computer% make clean computer% make computer% ./game
Makefile. MAKE SURE YOUR NAME IS ON THE TOP OF EACH FILE (except the Makefile)! Use
jbsartoras the grader and
assign7Mulliganif it is late) as the assignment name.
computer% turnin --submit jbsartor assign7 (all .h and .cpp files) Makefile
Make your concrete Life class a template class instead: