Player -> player_t
This commit is contained in:
parent
9e44d5144b
commit
83020d9120
8 changed files with 49 additions and 49 deletions
|
@ -30,7 +30,7 @@ CTTRTSGame& CTTRTSGame::operator=(CTTRTSGame&& game)
|
|||
}
|
||||
|
||||
// Interpret a string of orders
|
||||
int CTTRTSGame::IssueOrders( Player player, const std::string& _orders )
|
||||
int CTTRTSGame::IssueOrders( player_t player, const std::string& _orders )
|
||||
{
|
||||
COrderVector orderVector;
|
||||
|
||||
|
@ -57,7 +57,7 @@ int CTTRTSGame::IssueOrders( Player player, const std::string& _orders )
|
|||
}
|
||||
|
||||
// Issue orders by vector to the game
|
||||
int CTTRTSGame::IssueOrders( Player player, const COrderVector& orders )
|
||||
int CTTRTSGame::IssueOrders( player_t player, const COrderVector& orders )
|
||||
{
|
||||
// verify all the orders
|
||||
for ( auto order : orders )
|
||||
|
@ -71,7 +71,7 @@ int CTTRTSGame::IssueOrders( Player player, const COrderVector& orders )
|
|||
}
|
||||
|
||||
// Issue a single order
|
||||
int CTTRTSGame::IssueOrder( Player player, const SOrder & order )
|
||||
int CTTRTSGame::IssueOrder( player_t player, const SOrder & order )
|
||||
{
|
||||
// Verify the order
|
||||
if ( VerifyOrder(player,order) )
|
||||
|
@ -366,7 +366,7 @@ int CTTRTSGame::AddUnits( CUnitVector&& units )
|
|||
}
|
||||
|
||||
// Verify any order
|
||||
int CTTRTSGame::VerifyOrder( Player player, const SOrder & order ) const
|
||||
int CTTRTSGame::VerifyOrder( player_t player, const SOrder & order ) const
|
||||
{
|
||||
int ret = 1;
|
||||
|
||||
|
@ -435,9 +435,9 @@ CUnit& CTTRTSGame::GetUnitByID( unit_id_t id )
|
|||
}
|
||||
|
||||
// Get a vector of the players in the current game
|
||||
std::vector<Player> CTTRTSGame::GetPlayers() const
|
||||
std::vector<player_t> CTTRTSGame::GetPlayers() const
|
||||
{
|
||||
std::vector<Player> players;
|
||||
std::vector<player_t> players;
|
||||
players.reserve(GetNumUnits());
|
||||
|
||||
// Grab all players
|
||||
|
@ -454,10 +454,10 @@ std::vector<Player> CTTRTSGame::GetPlayers() const
|
|||
}
|
||||
|
||||
// Check if we have a win state
|
||||
Player CTTRTSGame::CheckForWin() const
|
||||
player_t CTTRTSGame::CheckForWin() const
|
||||
{
|
||||
// Array of units for each Player
|
||||
unsigned int units[(int) Player::NUM_INVALID];
|
||||
unsigned int units[(int) player_t::NUM_INVALID];
|
||||
memset(units,0,sizeof(units));
|
||||
|
||||
// Count up all the units for each Player
|
||||
|
@ -468,21 +468,21 @@ Player CTTRTSGame::CheckForWin() const
|
|||
}
|
||||
|
||||
// Default winning Player to invalid (no win)
|
||||
Player winningPlayer = Player::NUM_INVALID;
|
||||
player_t winningPlayer = player_t::NUM_INVALID;
|
||||
|
||||
// For each of the players
|
||||
for ( unsigned int i = 0; i < _countof(units); i++ )
|
||||
{
|
||||
// if there are still units in this Player, and the winning Player hasn't been set
|
||||
if( units[i] > 0 && winningPlayer == Player::NUM_INVALID )
|
||||
if( units[i] > 0 && winningPlayer == player_t::NUM_INVALID )
|
||||
{
|
||||
winningPlayer = (Player)i;
|
||||
winningPlayer = (player_t)i;
|
||||
}
|
||||
// Otherwise, if there are units in this Player and the winning Player HAS been set
|
||||
else if ( units[i] > 0 )
|
||||
{
|
||||
// Set back to invalid and break out of the loop
|
||||
winningPlayer = Player::NUM_INVALID;
|
||||
winningPlayer = player_t::NUM_INVALID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,15 +33,15 @@ public:
|
|||
// Check for a win, returns invalid for no win state reached
|
||||
// Note: this function will return invalid a draw was reached
|
||||
// best practice would be to call with GetNumUnits() == 0
|
||||
Player CheckForWin() const;
|
||||
player_t CheckForWin() const;
|
||||
|
||||
// Get the game information as a string
|
||||
std::string GetStateAsString() const;
|
||||
|
||||
// Issue orders to the game, returns non-zero if orders are incorrect
|
||||
int IssueOrders( Player player, const std::string& orders );
|
||||
int IssueOrders( Player player, const COrderVector& orders );
|
||||
int IssueOrder( Player player, const SOrder & order );
|
||||
int IssueOrders( player_t player, const std::string& orders );
|
||||
int IssueOrders( player_t player, const COrderVector& orders );
|
||||
int IssueOrder( player_t player, const SOrder & order );
|
||||
|
||||
// Add a units to the game, nonzero return value indicates error
|
||||
int AddUnit( CUnit&& unit );
|
||||
|
@ -71,7 +71,7 @@ public:
|
|||
inline int GetTurn() const { return turn; }
|
||||
|
||||
// Get a vector of the players in the current game
|
||||
std::vector<Player> GetPlayers() const;
|
||||
std::vector<player_t> GetPlayers() const;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -79,7 +79,7 @@ private:
|
|||
static bool CheckForPassThrough( const CUnit& one, const CUnit& two );
|
||||
|
||||
// Verify any order or position - non-zero is error
|
||||
int VerifyOrder( Player player, const SOrder & order ) const;
|
||||
int VerifyOrder( player_t player, const SOrder & order ) const;
|
||||
int VerifyPos( uvector2 vec ) const;
|
||||
|
||||
// Get a units new position after an order
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <limits> // std::numeric_limits
|
||||
|
||||
// Type for a Player IDs
|
||||
enum class Player : char
|
||||
enum class player_t : char
|
||||
{
|
||||
Red = 0,
|
||||
Green,
|
||||
|
|
|
@ -88,7 +88,7 @@ CUnit CUnit::GetUnitFromString(const std::string& unit )
|
|||
&posy );
|
||||
|
||||
ret.unit_id = (unit_id_t)id;
|
||||
ret.player_id = (Player) player;
|
||||
ret.player_id = (player_t) player;
|
||||
ret.unit_vis = (unitvis_c)vis;
|
||||
ret.dir = (dir_t)dir;
|
||||
ret.pos = uvector2(posx,posy);
|
||||
|
@ -99,7 +99,7 @@ CUnit CUnit::GetUnitFromString(const std::string& unit )
|
|||
// Plain constructor
|
||||
CUnit::CUnit()
|
||||
: unit_id ( get_unique_unit_id() )
|
||||
, player_id ( Player::NUM_INVALID )
|
||||
, player_id ( player_t::NUM_INVALID )
|
||||
, unit_vis (unitvis_invalid)
|
||||
, dir ( dir_t::S )
|
||||
, pos ( { ucoord_invalid, ucoord_invalid } )
|
||||
|
|
|
@ -36,13 +36,13 @@ public:
|
|||
|
||||
// Getters for all the members
|
||||
inline const unit_id_t& GetID() const { return unit_id; }
|
||||
inline const Player & GetPlayer() const { return player_id; }
|
||||
inline const player_t & GetPlayer() const { return player_id; }
|
||||
inline const unitvis_c & GetVisual() const { return unit_vis; }
|
||||
inline const dir_t& GetDir() const { return dir; }
|
||||
inline const uvector2& GetPos() const { return pos; }
|
||||
|
||||
// Set
|
||||
inline Player SetPlayer(const Player &v) { return (player_id = v); }
|
||||
inline player_t SetPlayer(const player_t &v) { return (player_id = v); }
|
||||
inline unitvis_c SetVisual(const unitvis_c &v) { return (unit_vis = v); }
|
||||
inline dir_t SetDir(const dir_t &v) { return (dir = v); }
|
||||
inline void SetPos(const uvector2 &v) { pos = v; }
|
||||
|
@ -73,7 +73,7 @@ private:
|
|||
unitvis_c unit_vis;
|
||||
|
||||
// Player ID
|
||||
Player player_id;
|
||||
player_t player_id;
|
||||
|
||||
// Direction
|
||||
dir_t dir;
|
||||
|
@ -90,7 +90,7 @@ typedef std::vector< unit_id_t > CUnitIDVector;
|
|||
inline bool CUnit::Valid() const
|
||||
{
|
||||
return (unit_id != unit_id_invalid )
|
||||
&& (player_id != Player::NUM_INVALID )
|
||||
&& (player_id != player_t::NUM_INVALID )
|
||||
&& (unit_vis != unitvis_invalid);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
void AddUnitToGame( Player player, char vis, uvector2 vec, CTTRTSGame& game )
|
||||
void AddUnitToGame( player_t player, char vis, uvector2 vec, CTTRTSGame& game )
|
||||
{
|
||||
CUnit unit = CUnit::GetUnitFromVis(vis);
|
||||
unit.SetPos(vec);
|
||||
|
@ -28,10 +28,10 @@ int main()
|
|||
CTTRTSGame game(6, 6);
|
||||
game.SetName("Tiny2v2");
|
||||
|
||||
AddUnitToGame( Player::Red, '<', uvector2(4, 2), game);
|
||||
AddUnitToGame( Player::Red, '<', uvector2(4, 4), game);
|
||||
AddUnitToGame( Player::Green, '>', uvector2(1, 1), game);
|
||||
AddUnitToGame( Player::Green, '>', uvector2(1, 3), game);
|
||||
AddUnitToGame( player_t::Red, '<', uvector2(4, 2), game);
|
||||
AddUnitToGame( player_t::Red, '<', uvector2(4, 4), game);
|
||||
AddUnitToGame( player_t::Green, '>', uvector2(1, 1), game);
|
||||
AddUnitToGame( player_t::Green, '>', uvector2(1, 3), game);
|
||||
|
||||
OutputGame(std::move(game));
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ int main()
|
|||
game.SetName("Big2v2");
|
||||
|
||||
for ( ucoord_t y : { 2,4,6,8,10 } )
|
||||
AddUnitToGame( Player::Red, '<', uvector2(18, y), game);
|
||||
AddUnitToGame( player_t::Red, '<', uvector2(18, y), game);
|
||||
for ( ucoord_t y : { 1,3,5,7,9 } )
|
||||
AddUnitToGame( Player::Green, '>', uvector2(1, y), game);
|
||||
AddUnitToGame( player_t::Green, '>', uvector2(1, y), game);
|
||||
|
||||
|
||||
OutputGame(std::move(game));
|
||||
|
@ -56,13 +56,13 @@ int main()
|
|||
game.SetName("Chess");
|
||||
|
||||
for ( ucoord_t y : { 1,3,5,7 } ) {
|
||||
AddUnitToGame(Player::Red, '<', uvector2(6, y), game);
|
||||
AddUnitToGame(Player::Red, '<', uvector2(7, y), game);
|
||||
AddUnitToGame(player_t::Red, '<', uvector2(6, y), game);
|
||||
AddUnitToGame(player_t::Red, '<', uvector2(7, y), game);
|
||||
}
|
||||
|
||||
for ( ucoord_t y : { 0,2,4,6 } ) {
|
||||
AddUnitToGame(Player::Green, '>', uvector2(0, y), game);
|
||||
AddUnitToGame(Player::Green, '>', uvector2(1, y), game);
|
||||
AddUnitToGame(player_t::Green, '>', uvector2(0, y), game);
|
||||
AddUnitToGame(player_t::Green, '>', uvector2(1, y), game);
|
||||
}
|
||||
|
||||
OutputGame(std::move(game));
|
||||
|
|
|
@ -36,7 +36,7 @@ const char* tests()
|
|||
{
|
||||
CUnit unit1;
|
||||
unit1.SetFromVisual('v');
|
||||
unit1.SetPlayer(Player::Green);
|
||||
unit1.SetPlayer(player_t::Green);
|
||||
unit1.SetPos(uvector2(5, 10));
|
||||
|
||||
std::string unit1Desc = CUnit::GetStringFromUnit(unit1);
|
||||
|
@ -82,7 +82,7 @@ const char* tests()
|
|||
{
|
||||
CUnit unit = CUnit::GetUnitFromVis('^');
|
||||
unit.SetPos({2, 2});
|
||||
unit.SetPlayer(Player::Red);
|
||||
unit.SetPlayer(player_t::Red);
|
||||
|
||||
game.AddUnit(std::move(unit));
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ const char* tests()
|
|||
{
|
||||
CUnit unit = CUnit::GetUnitFromVis('^');
|
||||
unit.SetPos({2, 2});
|
||||
unit.SetPlayer(Player::Red);
|
||||
unit.SetPlayer(player_t::Red);
|
||||
|
||||
if( !game.AddUnit(std::move(unit)) )
|
||||
return "Game should have rejected unit placed on the same spot";
|
||||
|
@ -109,7 +109,7 @@ const char* tests()
|
|||
SOrder order;
|
||||
|
||||
unit.SetPos({2, 2});
|
||||
unit.SetPlayer(Player::Red);
|
||||
unit.SetPlayer(player_t::Red);
|
||||
|
||||
if ( game.AddUnit(std::move(unit)) )
|
||||
return "Game failed to add valid unit";
|
||||
|
@ -117,7 +117,7 @@ const char* tests()
|
|||
order.unit = id;
|
||||
order.command = command_c::F;
|
||||
|
||||
if( game.IssueOrder(Player::Red,order) )
|
||||
if( game.IssueOrder(player_t::Red,order) )
|
||||
return "Game failed to issue valid order";
|
||||
|
||||
if (game.SimulateToNextTurn() )
|
||||
|
@ -140,7 +140,7 @@ const char* tests()
|
|||
SOrder order;
|
||||
|
||||
unit.SetPos({0, 0});
|
||||
unit.SetPlayer(Player::Blue);
|
||||
unit.SetPlayer(player_t::Blue);
|
||||
|
||||
if ( game.AddUnit(std::move(unit)) )
|
||||
return "Game failed to add valid unit";
|
||||
|
@ -148,14 +148,14 @@ const char* tests()
|
|||
order.unit = id;
|
||||
order.command = command_c::A;
|
||||
|
||||
if( game.IssueOrder(Player::Blue,order) )
|
||||
if( game.IssueOrder(player_t::Blue,order) )
|
||||
return "Game failed to issue valid order";
|
||||
}
|
||||
{
|
||||
CUnit unit = CUnit::GetUnitFromVis('<');
|
||||
|
||||
unit.SetPos({1, 0});
|
||||
unit.SetPlayer(Player::Red);
|
||||
unit.SetPlayer(player_t::Red);
|
||||
|
||||
if ( game.AddUnit(std::move(unit)) )
|
||||
return "Game failed to add valid unit";
|
||||
|
@ -172,7 +172,7 @@ const char* tests()
|
|||
if (game.GetUnitByIndex(0).GetID() != id )
|
||||
return "Game killed the wrong unit";
|
||||
|
||||
if ( game.CheckForWin() != Player::Blue )
|
||||
if ( game.CheckForWin() != player_t::Blue )
|
||||
return "Game failed to recognise a win for the right Player";
|
||||
|
||||
std::string game_string = game.GetStateAsString();
|
||||
|
|
|
@ -134,8 +134,8 @@ int main(int argc, char* argv[])
|
|||
system(cmd1);
|
||||
|
||||
// While the game hasn't been won
|
||||
Player winningPlayer;
|
||||
while ( ((winningPlayer = game.CheckForWin()) == Player::NUM_INVALID) // We have a winning player
|
||||
player_t winningPlayer;
|
||||
while ( ((winningPlayer = game.CheckForWin()) == player_t::NUM_INVALID) // We have a winning player
|
||||
&& game.GetNumUnits() > 0 ) // We have no units left
|
||||
{
|
||||
std::cout<<"Starting turn "<<game.GetTurn()<<std::endl;
|
||||
|
@ -148,7 +148,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
// Wait for order files
|
||||
for( Player player : players)
|
||||
for( player_t player : players)
|
||||
{
|
||||
// Construct the player order filename
|
||||
char playerOrderFileName[128];
|
||||
|
@ -221,7 +221,7 @@ int main(int argc, char* argv[])
|
|||
OutputGameStateFile(game, gameDir);
|
||||
|
||||
// Print the winner!
|
||||
if ( winningPlayer != Player::NUM_INVALID )
|
||||
if ( winningPlayer != player_t::NUM_INVALID )
|
||||
{
|
||||
std::cout<<"Game over! Winner:"<<(int) winningPlayer <<std::endl;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue