//GameOfLife.h file #pragma once #include // Provides ostream #include // String
ID: 3799608 • Letter: #
Question
//GameOfLife.h file
#pragma once
#include // Provides ostream
#include // String operations
#include // Randomizer
namespace csci2312{
using std::string;
using std::ostream;
using std::istream;
class Cell{
friend class GameOfLife;
public:
static const char alive ='o'; // alive image
static const char dead = '-'; // dead image
// Default constructor sets the cell's state to false
Cell();
// Custom constructor sets the cell's state as per argument
Cell(bool state);
// Empty destructor~Cell();
// Accessors have no intention to modify the object, so it is a good
practice to make them 'const' functions
bool getState() const;
// Mutator to change cell's state
void setState(bool newState);
// Accessor to see the 'face'
char getFace() const;
private:
bool state;char face;
};
class GameOfLife
{
public:
static const unsigned int MAX_BOARD = 30;
GameOfLife();
GameOfLife(size_t boardSize);
~GameOfLife();
int seedBoard(string fileName);
void seedBoard(size_t seeds);void run();
void run(unsigned int numberOfIterations);
// ADVANCED// A const(!) accessor method that returns a handle to the private
currentLife array.
// The return type must also be 'const' because we return a pointer
to a static array, and these are fixed
// It is just an example. It is not needed if we have a friend operator.
const Cell(*getCurrentLife() const )[MAX_BOARD+2] { return
currentLife;
};
///////////////////////////////////////////////////////
// friend operator can access private members of GameOfLife
friend ostream& operator << (ostream& out, const GameOfLife& board);
friend istream& operator >> (istream& in, GameOfLife& board);
private:
bool executeRules(unsigned int countAlive, bool currentState);
// With "Halo" approach we need a bigger board
Cell currentLife[MAX_BOARD + 2][MAX_BOARD + 2];
Cell nextLife[MAX_BOARD + 2][MAX_BOARD + 2];
// ADVANCED// Example how to declare variable cl as a pointer/handle to our
array of Cells of size HALO_BOARD
// The accessor method getCurrentLife() above uses the same syntax
for the return type
const Cell(*cl)[MAX_BOARD + 2] = currentLife;////////////////////////////////////////////////////////
size_t boardSize; // Board size requested in the constructor
}; // NON-MEMBER OUTPUT FUNCTIONS
// Display cell's state with alive/dead face
ostream& operator << (ostream& out, const Cell& cell);
}
Here is provided GameOfLife.h file, I need GameOfLife.cpp and main.cpp file, Can someone help on this problem?
Explanation / Answer
void main()
}
}
if(board[y][x]>0 && board[y][x]<9)
revealed[y][x] = 1;
} while(dead == 0);
if (dead == 1)
replay();
}
void replay()
>= ran / (ran * i) + (i * 1337);
ran = {ran down|spent|exhausted|used up|depleted|expended|worn-out|wiped out|burnt up|dried-up" id="tip_18">burnt up b;
come back ran;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.