Add new game string outputer and use it.
modify some of the other outputters to look better
This commit is contained in:
parent
24ac058475
commit
002c1e5927
5 changed files with 39 additions and 2 deletions
|
@ -218,6 +218,9 @@ int CTTRTSGame::SimulateToNextTurn()
|
||||||
pair.order = COrder();
|
pair.order = COrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Increment the current turn
|
||||||
|
turn++;
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,3 +355,26 @@ Team CTTRTSGame::CheckForWin() const
|
||||||
|
|
||||||
return winningTeam;
|
return winningTeam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the game information as a string
|
||||||
|
std::string CTTRTSGame::GetStateAsString() const
|
||||||
|
{
|
||||||
|
// Print out the header
|
||||||
|
char header[64];
|
||||||
|
snprintf(header, 512, GAME_HEADER_FORMATTER , turn, dimensions.x, dimensions.y );
|
||||||
|
|
||||||
|
// Gather unit information
|
||||||
|
std::string units;
|
||||||
|
for ( const OrderUnitPair& pair : m_OrderUnitPairs )
|
||||||
|
{
|
||||||
|
units += GetStringFromUnit(pair.unit);
|
||||||
|
units += '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append the header and units
|
||||||
|
std::string state(header);
|
||||||
|
state += '\n';
|
||||||
|
state += units;
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
|
@ -36,6 +36,7 @@ public:
|
||||||
|
|
||||||
CTTRTSGame( ucoord_t c, ucoord_t r )
|
CTTRTSGame( ucoord_t c, ucoord_t r )
|
||||||
: dimensions( c,r )
|
: dimensions( c,r )
|
||||||
|
, turn (0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -80,6 +81,9 @@ public:
|
||||||
// best practice would be to call with GetNumUnits() == 0
|
// best practice would be to call with GetNumUnits() == 0
|
||||||
Team CheckForWin() const;
|
Team CheckForWin() const;
|
||||||
|
|
||||||
|
// Get the game information as a string
|
||||||
|
std::string GetStateAsString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Verify any order - non-zero is error
|
// Verify any order - non-zero is error
|
||||||
|
@ -102,6 +106,11 @@ private:
|
||||||
|
|
||||||
// Dimensions of the game
|
// Dimensions of the game
|
||||||
uvector2 dimensions;
|
uvector2 dimensions;
|
||||||
|
|
||||||
|
// Int to store the current turn
|
||||||
|
unsigned int turn;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define GAME_HEADER_FORMATTER "===== GAME TURN =====\nSIZE:[%u,%u]\nTURN:%u"
|
||||||
|
|
||||||
#endif //_GAME_H_
|
#endif //_GAME_H_
|
||||||
|
|
|
@ -45,7 +45,7 @@ inline bool COrder::operator== ( const COrder& rhs ) const
|
||||||
// Typedef a vector of orders
|
// Typedef a vector of orders
|
||||||
typedef std::vector<COrder> COrderVector;
|
typedef std::vector<COrder> COrderVector;
|
||||||
|
|
||||||
#define ORDER_FORMATTER "ORDER co:%c un:%u"
|
#define ORDER_FORMATTER "ORDER:%c id:%u"
|
||||||
|
|
||||||
// string <--> order conversion functions
|
// string <--> order conversion functions
|
||||||
std::string GetStringFromOrder(const COrder& order );
|
std::string GetStringFromOrder(const COrder& order );
|
||||||
|
|
|
@ -100,7 +100,7 @@ inline bool CUnit::valid() const
|
||||||
CUnit GetUnitFromVis( unitVis_c vis );
|
CUnit GetUnitFromVis( unitVis_c vis );
|
||||||
|
|
||||||
// Unit <--> string conversion functions
|
// Unit <--> string conversion functions
|
||||||
#define UNIT_FORMATTER "UNIT id:%u tm:%u pl:%u vs:%c dr:%c ps:%u,%u"
|
#define UNIT_FORMATTER "UNIT:%u tm:%u pl:%u vs:%c dr:%c ps:[%u,%u]"
|
||||||
std::string GetStringFromUnit(const CUnit& unit );
|
std::string GetStringFromUnit(const CUnit& unit );
|
||||||
CUnit GetUnitFromString(const std::string& unit );
|
CUnit GetUnitFromString(const std::string& unit );
|
||||||
|
|
||||||
|
|
|
@ -180,6 +180,8 @@ const char* tests()
|
||||||
|
|
||||||
if ( game.CheckForWin() != Team::Blue )
|
if ( game.CheckForWin() != Team::Blue )
|
||||||
return "Game failed to recognise a win for the right Team";
|
return "Game failed to recognise a win for the right Team";
|
||||||
|
|
||||||
|
std::cout<<game.GetStateAsString()<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue