From a90ad9f90cfb7d5b3a1b6bd8e135ba251210c0f5 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Tue, 16 Dec 2014 13:13:03 +0000 Subject: [PATCH] Remove player IDs, keep it simple stupid --- games/Basic_5_v_5.txt | 20 ++++++++++---------- source/game/game.cpp | 14 +++++++------- source/game/game.h | 8 ++++---- source/game/gametypes.h | 2 -- source/game/unit.cpp | 8 -------- source/game/unit.h | 8 +------- source/gen/gen.cpp | 23 +++++++++++------------ source/test/test.cpp | 10 ++-------- 8 files changed, 35 insertions(+), 58 deletions(-) diff --git a/games/Basic_5_v_5.txt b/games/Basic_5_v_5.txt index c4aeb10..6ea6afb 100644 --- a/games/Basic_5_v_5.txt +++ b/games/Basic_5_v_5.txt @@ -2,13 +2,13 @@ SIZE:[21,11] TURN:0 ~~~~ -UNIT:0 tm:1 pl:0 vs:> dr:E ps:[1,1] -UNIT:1 tm:1 pl:0 vs:> dr:E ps:[1,3] -UNIT:2 tm:1 pl:0 vs:> dr:E ps:[1,5] -UNIT:3 tm:1 pl:0 vs:> dr:E ps:[1,7] -UNIT:4 tm:1 pl:0 vs:> dr:E ps:[1,9] -UNIT:5 tm:0 pl:1 vs:< dr:W ps:[19,1] -UNIT:6 tm:0 pl:1 vs:< dr:W ps:[19,3] -UNIT:7 tm:0 pl:1 vs:< dr:W ps:[19,5] -UNIT:8 tm:0 pl:1 vs:< dr:W ps:[19,7] -UNIT:9 tm:0 pl:1 vs:< dr:W ps:[19,9] +UNIT:0 tm:1 vs:> dr:E ps:[1,1] +UNIT:1 tm:1 vs:> dr:E ps:[1,3] +UNIT:2 tm:1 vs:> dr:E ps:[1,5] +UNIT:3 tm:1 vs:> dr:E ps:[1,7] +UNIT:4 tm:1 vs:> dr:E ps:[1,9] +UNIT:5 tm:0 vs:< dr:W ps:[19,1] +UNIT:6 tm:0 vs:< dr:W ps:[19,3] +UNIT:7 tm:0 vs:< dr:W ps:[19,5] +UNIT:8 tm:0 vs:< dr:W ps:[19,7] +UNIT:9 tm:0 vs:< dr:W ps:[19,9] diff --git a/source/game/game.cpp b/source/game/game.cpp index c3d8df4..1f811e5 100644 --- a/source/game/game.cpp +++ b/source/game/game.cpp @@ -30,7 +30,7 @@ CTTRTSGame& CTTRTSGame::operator=(CTTRTSGame&& game) } // Interpret a string of orders -int CTTRTSGame::IssueOrders( player_id_t player, const std::string& _orders ) +int CTTRTSGame::IssueOrders( Team team, const std::string& _orders ) { COrderVector orderVector; @@ -53,17 +53,17 @@ int CTTRTSGame::IssueOrders( player_id_t player, const std::string& _orders ) } // Call our add order by vector method - return IssueOrders(player,orderVector); + return IssueOrders(team,orderVector); } // Issue orders by vector to the game -int CTTRTSGame::IssueOrders( player_id_t player, const COrderVector& orders ) +int CTTRTSGame::IssueOrders( Team team, const COrderVector& orders ) { // verify all the orders for ( auto order : orders ) { // If any order returns non-zero, back out - if ( IssueOrder(player,order) ) + if ( IssueOrder(team,order) ) return 1; } @@ -71,10 +71,10 @@ int CTTRTSGame::IssueOrders( player_id_t player, const COrderVector& orders ) } // Issue a single order -int CTTRTSGame::IssueOrder( player_id_t player, const COrder& order ) +int CTTRTSGame::IssueOrder( Team team, const COrder& order ) { // Verify the order - if ( VerifyOrder(player,order) ) + if ( VerifyOrder(team,order) ) return 1; // Get the right unit for the order @@ -290,7 +290,7 @@ int CTTRTSGame::AddUnits( CUnitVector&& units ) } // Verify any order -int CTTRTSGame::VerifyOrder( player_id_t player, const COrder& order ) const +int CTTRTSGame::VerifyOrder( Team team, const COrder& order ) const { int ret = 1; diff --git a/source/game/game.h b/source/game/game.h index a218b92..b0c3fad 100644 --- a/source/game/game.h +++ b/source/game/game.h @@ -68,9 +68,9 @@ public: std::string GetStateAsString() const; // Issue orders to the game, returns non-zero if orders are incorrect - int IssueOrders( player_id_t player, const std::string& orders ); - int IssueOrders( player_id_t player, const COrderVector& orders ); - int IssueOrder( player_id_t player, const COrder& order ); + int IssueOrders( Team team, const std::string& orders ); + int IssueOrders( Team team, const COrderVector& orders ); + int IssueOrder( Team team, const COrder& order ); // Add a units to the game, nonzero return value indicates error int AddUnit( CUnit&& unit ); @@ -100,7 +100,7 @@ public: private: // Verify any order or position - non-zero is error - int VerifyOrder( player_id_t player, const COrder& order ) const; + int VerifyOrder( Team team, const COrder& order ) const; int VerifyPos( uvector2 vec ) const; // Get a units new position after an order diff --git a/source/game/gametypes.h b/source/game/gametypes.h index b603cf9..c3ce010 100644 --- a/source/game/gametypes.h +++ b/source/game/gametypes.h @@ -14,11 +14,9 @@ enum class Team : char }; -typedef unsigned char player_id_t; // Type for player IDs typedef unsigned short unit_id_t; // Type for unit IDs typedef char unitVis_c; // Typedef for unit visual representations -static const player_id_t player_id_invalid = std::numeric_limits::max(); static const unit_id_t unit_id_invalid = std::numeric_limits::max(); static const unitVis_c unitVis_invalid = std::numeric_limits::max(); diff --git a/source/game/unit.cpp b/source/game/unit.cpp index d7470d0..4bdaaa8 100644 --- a/source/game/unit.cpp +++ b/source/game/unit.cpp @@ -48,7 +48,6 @@ std::string CUnit::GetStringFromUnit(const CUnit& unit ) snprintf(buff,128, UNIT_FORMATTER, unit.unit_id, (int)unit.team_id, - unit.player_id, unit.unit_vis, unit.dir, unit.pos.x, @@ -65,7 +64,6 @@ CUnit CUnit::GetUnitFromString(const std::string& unit ) unsigned int id; int team; - unsigned int player; char vis; char dir; unsigned int posx; @@ -74,7 +72,6 @@ CUnit CUnit::GetUnitFromString(const std::string& unit ) sscanf(unit.c_str(), UNIT_FORMATTER, &id, &team, - &player, &vis, &dir, &posx, @@ -82,7 +79,6 @@ CUnit CUnit::GetUnitFromString(const std::string& unit ) ret.unit_id = (unit_id_t)id; ret.team_id = (Team)team; - ret.player_id = (player_id_t)player; ret.unit_vis = (unitVis_c)vis; ret.dir = (dir_t)dir; ret.pos = uvector2(posx,posy); @@ -95,7 +91,6 @@ CUnit::CUnit() : unit_id ( get_unique_unit_id() ) , team_id ( Team::NUM_INVALID ) , unit_vis ( unitVis_invalid ) -, player_id ( player_id_invalid ) , dir ( dir_t::S ) , pos ( { ucoord_invalid, ucoord_invalid } ) { @@ -106,7 +101,6 @@ CUnit::CUnit() CUnit::CUnit(CUnit&& unit) : unit_id ( std::move(unit.unit_id) ) , team_id ( std::move(unit.team_id) ) -, player_id ( std::move(unit.player_id) ) , unit_vis ( std::move(unit.unit_vis) ) , dir ( std::move(unit.dir) ) , pos ( std::move(unit.pos) ) @@ -120,7 +114,6 @@ CUnit& CUnit::operator=(CUnit&& unit) { unit_id = std::move(unit.unit_id) ; team_id = std::move(unit.team_id) ; - player_id = std::move(unit.player_id) ; unit_vis = std::move(unit.unit_vis) ; dir = std::move(unit.dir) ; pos = std::move(unit.pos) ; @@ -132,7 +125,6 @@ bool CUnit::operator==(const CUnit& rhs) { return (unit_id == rhs.unit_id) && (team_id == rhs.team_id) - && (player_id == rhs.player_id) && (unit_vis == rhs.unit_vis) && (dir == rhs.dir) && (pos == rhs.pos); diff --git a/source/game/unit.h b/source/game/unit.h index cd9cff7..90003b5 100644 --- a/source/game/unit.h +++ b/source/game/unit.h @@ -7,7 +7,7 @@ #include "gametypes.h" #include "vector2.h" -#define UNIT_FORMATTER "UNIT:%u tm:%u pl:%u vs:%c dr:%c ps:[%u,%u]" +#define UNIT_FORMATTER "UNIT:%u tm:%u vs:%c dr:%c ps:[%u,%u]" // Base unit type class CUnit @@ -37,14 +37,12 @@ public: // Getters for all the members inline const unit_id_t& getID() const { return unit_id; } inline const Team & getTeam() const { return team_id; } - inline const player_id_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 Team setTeam(const Team & v) { return (team_id = v); } - inline player_id_t setPlayer(const player_id_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; } @@ -77,9 +75,6 @@ private: // Team ID Team team_id; - // Owner ID - player_id_t player_id; - // Direction dir_t dir; @@ -95,7 +90,6 @@ inline bool CUnit::valid() const { return (unit_id != unit_id_invalid ) && (team_id != Team::NUM_INVALID ) - && (player_id != player_id_invalid) && (unit_vis != unitVis_invalid); } diff --git a/source/gen/gen.cpp b/source/gen/gen.cpp index f020348..d598d89 100644 --- a/source/gen/gen.cpp +++ b/source/gen/gen.cpp @@ -3,11 +3,10 @@ #include #include -void AddUnitToGame( player_id_t player, Team team, char vis, uvector2 vec, CTTRTSGame& game ) +void AddUnitToGame( Team team, char vis, uvector2 vec, CTTRTSGame& game ) { CUnit unit = CUnit::GetUnitFromVis(vis); unit.setPos( vec ); - unit.setPlayer(player); unit.setTeam(team); game.AddUnit(std::move(unit)); } @@ -27,17 +26,17 @@ int main() CTTRTSGame game(21, 11); game.SetName("Basic_5_v_5"); - AddUnitToGame(0, Team::Blue, '>', uvector2(1, 1), game); - AddUnitToGame(0, Team::Blue, '>', uvector2(1, 3), game); - AddUnitToGame(0, Team::Blue, '>', uvector2(1, 5), game); - AddUnitToGame(0, Team::Blue, '>', uvector2(1, 7), game); - AddUnitToGame(0, Team::Blue, '>', uvector2(1, 9), game); + AddUnitToGame( Team::Blue, '>', uvector2(1, 1), game); + AddUnitToGame( Team::Blue, '>', uvector2(1, 3), game); + AddUnitToGame( Team::Blue, '>', uvector2(1, 5), game); + AddUnitToGame( Team::Blue, '>', uvector2(1, 7), game); + AddUnitToGame( Team::Blue, '>', uvector2(1, 9), game); - AddUnitToGame(1, Team::Red, '<', uvector2(19, 1), game); - AddUnitToGame(1, Team::Red, '<', uvector2(19, 3), game); - AddUnitToGame(1, Team::Red, '<', uvector2(19, 5), game); - AddUnitToGame(1, Team::Red, '<', uvector2(19, 7), game); - AddUnitToGame(1, Team::Red, '<', uvector2(19, 9), game); + AddUnitToGame( Team::Red, '<', uvector2(19, 1), game); + AddUnitToGame( Team::Red, '<', uvector2(19, 3), game); + AddUnitToGame( Team::Red, '<', uvector2(19, 5), game); + AddUnitToGame( Team::Red, '<', uvector2(19, 7), game); + AddUnitToGame( Team::Red, '<', uvector2(19, 9), game); OutputGame(game); } diff --git a/source/test/test.cpp b/source/test/test.cpp index b604f92..fdabe5b 100644 --- a/source/test/test.cpp +++ b/source/test/test.cpp @@ -37,7 +37,6 @@ const char* tests() { CUnit unit1; unit1.setFromVisual('v'); - unit1.setPlayer(0); unit1.setTeam(Team::Green); unit1.setPos( uvector2(5,10) ); @@ -84,7 +83,6 @@ const char* tests() { CUnit unit = CUnit::GetUnitFromVis('^'); unit.setPos( {2,2} ); - unit.setPlayer(0); unit.setTeam(Team::Red); game.AddUnit(std::move(unit)); @@ -93,7 +91,6 @@ const char* tests() { CUnit unit = CUnit::GetUnitFromVis('^'); unit.setPos( {2,2} ); - unit.setPlayer(0); unit.setTeam(Team::Red); if( !game.AddUnit(std::move(unit)) ) @@ -113,7 +110,6 @@ const char* tests() COrder order; unit.setPos( {2,2} ); - unit.setPlayer(0); unit.setTeam(Team::Red); if ( game.AddUnit(std::move(unit)) ) @@ -122,7 +118,7 @@ const char* tests() order.unit = id; order.command = command_c::F; - if( game.IssueOrder(0,order) ) + if( game.IssueOrder(Team::Red,order) ) return "Game failed to issue valid order"; if (game.SimulateToNextTurn() ) @@ -145,7 +141,6 @@ const char* tests() COrder order; unit.setPos( {0,0} ); - unit.setPlayer(1); unit.setTeam(Team::Blue); if ( game.AddUnit(std::move(unit)) ) @@ -154,14 +149,13 @@ const char* tests() order.unit = id; order.command = command_c::A; - if( game.IssueOrder(0,order) ) + if( game.IssueOrder(Team::Blue,order) ) return "Game failed to issue valid order"; } { CUnit unit = CUnit::GetUnitFromVis('<'); unit.setPos( {1,0} ); - unit.setPlayer(2); unit.setTeam(Team::Red); if ( game.AddUnit(std::move(unit)) )