Question: #ifndef GAME _ STATE _ H #define GAME _ STATE _ H #include #include #include #include struct Vec { int x; int y; Vec (
#ifndef GAMESTATEH
#define GAMESTATEH
#include
#include
#include
#include
struct Vec
int x;
int y;
Vec
x ;
y ;
Vecint x int y
thisx x;
thisy y;
void setint x int y
thisx x;
thisy y;;
std::ostream& operatorstd::ostream& os const Vec& v
os vx vy ;
return os;
struct GameState;
std::ostream& operatorstd::ostream& os const GameState& state;
struct GameState
int grid;
bool currentTurn;
int size;
int turnCount;
bool done;
Vec lastMove;
GameState
size ;
currentTurn ;
turnCount ;
done false;
lastMove.set;
grid new intsize;
for int i ; i size; i
gridi new intsize;
for int j ; j size; j
gridij;
GameStateint size
thissize size;
currentTurn ;
turnCount ;
done false;
lastMove.set;
grid new intsize;
for int i ; i size; i
gridi new intsize;
for int j ; j size; j
gridij;
GameStateconst GameState& other
size other.size;
currentTurn other.currentTurn;
turnCount other.turnCount;
done other.done;
lastMove other.lastMove;
grid new intsize;
for int i ; i size; i
gridi new intsize;
for int j ; j size; j
gridij other.gridij;
bool operatorconst GameState& other
bool sizeMatch size other.size;
bool currentTurnMatch currentTurn other.currentTurn;
bool turnCountMatch turnCount other.turnCount;
bool doneMatch done other.done;
bool lastMoveMatch lastMove.x other.lastMove.x && lastMove.y other.lastMove.y;
if sizeMatch && currentTurnMatch && turnCountMatch && doneMatch && lastMoveMatch
for int i ; i size; i
for int j ; j size; j
if gridij other.gridij
return false;
return true;
else
return false;
GameState& operatorconst GameState& other
currentTurn other.currentTurn;
turnCount other.turnCount;
done other.done;
lastMove other.lastMove;
if size other.size
for int i ; i size; i
for int j ; j size; j
gridij other.gridij;
else
for int i ; i size; i
delete gridi;
delete grid;
size other.size;
grid new intsize;
for int i ; i size; i
gridi new intsize;
for int j ; j size; j
gridij other.gridij;
return this;
bool hasWonint player
for int i ; i size; i
int count ;
for int j ; j size; j
if gridij player
count;
if count size
return true;
for int i ; i size; i
int count ;
for int j ; j size; j
if gridji player
count;
if count size
return true;
int mainDiagCount ;
for int i ; i size; i
if gridii player
mainDiagCount;
if mainDiagCount size
return true;
int secondaryDiagCount ;
for int i ; i size; i
if gridisizei player
secondaryDiagCount;
if secondaryDiagCount size
return true;
return false;
bool playint x int y
if gridxy
return false;
gridxy currentTurn;
currentTurn currentTurn;
turnCount;
lastMove.setx y;
if turnCount size size
done true;
else if hasWon hasWon
done true;
return true;
~GameState
for int i ; i size; i
delete gridi;
delete grid;;
std::ostream& operatorstd::ostream& os const GameState& state
os ;
for int j ; j state.size; j
os j ;
os std::endl;
os
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
