// LifeGame.doc documents LifeGame, a class for playing the game of Life.
// Author: Joel Adams, for Hands On C++.
// Date: November 1997.
//
#ifndef LIFE_GAME
#define LIFE_GAME
#include <iostream> // istream
#include <string> // string
#include <cassert> // assert()
#include <vector> // vector<>
using namespace std;
class LifeGame
{
public:
// **************************************************
// * LifeGame constructor. *
// * Receive: fileName, a string. *
// * Precondition: fileName contains the name of *
// * a file containing a Life configuration *
// * (the number of rows, the number of columns, *
// * and the values of each cell). *
// * Postcondition: myGrid has been initialized *
// * to the configuration in fileName. *
// **************************************************
LifeGame(const string & fileName);
// ***************************************************
// * LifeGame Rows extractor. *
// * Return: the number of rows in my configuration. *
// ***************************************************
int Rows() const;
// ******************************************************
// * LifeGame Columns extractor. *
// * Return: the number of columns in my configuration. *
// ******************************************************
int Columns() const;
// ******************************************************
// * Generate next LifeGame generation. *
// * Postcondition: For each cell myGrid[r][c]: *
// * if myGrid[r][c] had 3 living neighbors: *
// * myGrid[r][c] contains a 1. *
// * if myGrid[r][c] had less than 2 neighbors OR *
// * myGrid[r][c] had more than 3 neighbors: *
// * myGrid[r][c] contains a 0. *
// ******************************************************
void NextGeneration();
// ******************************************************
// * LifeGame Print function member. *
// * Receive: out, an ostream. *
// * Output: my configuration. *
// * Passback: out, containing my configuration. *
// ******************************************************
void Print(ostream & out) const;
private:
};
//********************************************************
// Ostream insertion operator. *
// Receive: out, an ostream, *
// theGame, a LifeGame. *
// Output: the configuration in theGame. *
// Passback: out, containing the output configuration. *
// Return: out, for chaining. *
//********************************************************
inline ostream & operator<<(ostream & out, const LifeGame & theGame)
{
theGame.Print(out);
return out;
}
/*
inline int LifeGame::Rows() const
{
}
*/
#endif