Remove player IDs, keep it simple stupid
This commit is contained in:
parent
e001396744
commit
a90ad9f90c
8 changed files with 35 additions and 58 deletions
|
@ -2,13 +2,13 @@
|
||||||
SIZE:[21,11]
|
SIZE:[21,11]
|
||||||
TURN:0
|
TURN:0
|
||||||
~~~~
|
~~~~
|
||||||
UNIT:0 tm:1 pl:0 vs:> dr:E ps:[1,1]
|
UNIT:0 tm:1 vs:> dr:E ps:[1,1]
|
||||||
UNIT:1 tm:1 pl:0 vs:> dr:E ps:[1,3]
|
UNIT:1 tm:1 vs:> dr:E ps:[1,3]
|
||||||
UNIT:2 tm:1 pl:0 vs:> dr:E ps:[1,5]
|
UNIT:2 tm:1 vs:> dr:E ps:[1,5]
|
||||||
UNIT:3 tm:1 pl:0 vs:> dr:E ps:[1,7]
|
UNIT:3 tm:1 vs:> dr:E ps:[1,7]
|
||||||
UNIT:4 tm:1 pl:0 vs:> dr:E ps:[1,9]
|
UNIT:4 tm:1 vs:> dr:E ps:[1,9]
|
||||||
UNIT:5 tm:0 pl:1 vs:< dr:W ps:[19,1]
|
UNIT:5 tm:0 vs:< dr:W ps:[19,1]
|
||||||
UNIT:6 tm:0 pl:1 vs:< dr:W ps:[19,3]
|
UNIT:6 tm:0 vs:< dr:W ps:[19,3]
|
||||||
UNIT:7 tm:0 pl:1 vs:< dr:W ps:[19,5]
|
UNIT:7 tm:0 vs:< dr:W ps:[19,5]
|
||||||
UNIT:8 tm:0 pl:1 vs:< dr:W ps:[19,7]
|
UNIT:8 tm:0 vs:< dr:W ps:[19,7]
|
||||||
UNIT:9 tm:0 pl:1 vs:< dr:W ps:[19,9]
|
UNIT:9 tm:0 vs:< dr:W ps:[19,9]
|
||||||
|
|
|
@ -30,7 +30,7 @@ CTTRTSGame& CTTRTSGame::operator=(CTTRTSGame&& game)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interpret a string of orders
|
// 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;
|
COrderVector orderVector;
|
||||||
|
|
||||||
|
@ -53,17 +53,17 @@ int CTTRTSGame::IssueOrders( player_id_t player, const std::string& _orders )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call our add order by vector method
|
// Call our add order by vector method
|
||||||
return IssueOrders(player,orderVector);
|
return IssueOrders(team,orderVector);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue orders by vector to the game
|
// 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
|
// verify all the orders
|
||||||
for ( auto order : orders )
|
for ( auto order : orders )
|
||||||
{
|
{
|
||||||
// If any order returns non-zero, back out
|
// If any order returns non-zero, back out
|
||||||
if ( IssueOrder(player,order) )
|
if ( IssueOrder(team,order) )
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,10 +71,10 @@ int CTTRTSGame::IssueOrders( player_id_t player, const COrderVector& orders )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue a single order
|
// 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
|
// Verify the order
|
||||||
if ( VerifyOrder(player,order) )
|
if ( VerifyOrder(team,order) )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// Get the right unit for the order
|
// Get the right unit for the order
|
||||||
|
@ -290,7 +290,7 @@ int CTTRTSGame::AddUnits( CUnitVector&& units )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify any order
|
// 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;
|
int ret = 1;
|
||||||
|
|
||||||
|
|
|
@ -68,9 +68,9 @@ public:
|
||||||
std::string GetStateAsString() const;
|
std::string GetStateAsString() const;
|
||||||
|
|
||||||
// Issue orders to the game, returns non-zero if orders are incorrect
|
// Issue orders to the game, returns non-zero if orders are incorrect
|
||||||
int IssueOrders( player_id_t player, const std::string& orders );
|
int IssueOrders( Team team, const std::string& orders );
|
||||||
int IssueOrders( player_id_t player, const COrderVector& orders );
|
int IssueOrders( Team team, const COrderVector& orders );
|
||||||
int IssueOrder( player_id_t player, const COrder& order );
|
int IssueOrder( Team team, const COrder& order );
|
||||||
|
|
||||||
// Add a units to the game, nonzero return value indicates error
|
// Add a units to the game, nonzero return value indicates error
|
||||||
int AddUnit( CUnit&& unit );
|
int AddUnit( CUnit&& unit );
|
||||||
|
@ -100,7 +100,7 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Verify any order or position - non-zero is error
|
// 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;
|
int VerifyPos( uvector2 vec ) const;
|
||||||
|
|
||||||
// Get a units new position after an order
|
// Get a units new position after an order
|
||||||
|
|
|
@ -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 unsigned short unit_id_t; // Type for unit IDs
|
||||||
typedef char unitVis_c; // Typedef for unit visual representations
|
typedef char unitVis_c; // Typedef for unit visual representations
|
||||||
|
|
||||||
static const player_id_t player_id_invalid = std::numeric_limits<player_id_t>::max();
|
|
||||||
static const unit_id_t unit_id_invalid = std::numeric_limits<unit_id_t>::max();
|
static const unit_id_t unit_id_invalid = std::numeric_limits<unit_id_t>::max();
|
||||||
static const unitVis_c unitVis_invalid = std::numeric_limits<unitVis_c>::max();
|
static const unitVis_c unitVis_invalid = std::numeric_limits<unitVis_c>::max();
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,6 @@ std::string CUnit::GetStringFromUnit(const CUnit& unit )
|
||||||
snprintf(buff,128, UNIT_FORMATTER,
|
snprintf(buff,128, UNIT_FORMATTER,
|
||||||
unit.unit_id,
|
unit.unit_id,
|
||||||
(int)unit.team_id,
|
(int)unit.team_id,
|
||||||
unit.player_id,
|
|
||||||
unit.unit_vis,
|
unit.unit_vis,
|
||||||
unit.dir,
|
unit.dir,
|
||||||
unit.pos.x,
|
unit.pos.x,
|
||||||
|
@ -65,7 +64,6 @@ CUnit CUnit::GetUnitFromString(const std::string& unit )
|
||||||
|
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
int team;
|
int team;
|
||||||
unsigned int player;
|
|
||||||
char vis;
|
char vis;
|
||||||
char dir;
|
char dir;
|
||||||
unsigned int posx;
|
unsigned int posx;
|
||||||
|
@ -74,7 +72,6 @@ CUnit CUnit::GetUnitFromString(const std::string& unit )
|
||||||
sscanf(unit.c_str(), UNIT_FORMATTER,
|
sscanf(unit.c_str(), UNIT_FORMATTER,
|
||||||
&id,
|
&id,
|
||||||
&team,
|
&team,
|
||||||
&player,
|
|
||||||
&vis,
|
&vis,
|
||||||
&dir,
|
&dir,
|
||||||
&posx,
|
&posx,
|
||||||
|
@ -82,7 +79,6 @@ CUnit CUnit::GetUnitFromString(const std::string& unit )
|
||||||
|
|
||||||
ret.unit_id = (unit_id_t)id;
|
ret.unit_id = (unit_id_t)id;
|
||||||
ret.team_id = (Team)team;
|
ret.team_id = (Team)team;
|
||||||
ret.player_id = (player_id_t)player;
|
|
||||||
ret.unit_vis = (unitVis_c)vis;
|
ret.unit_vis = (unitVis_c)vis;
|
||||||
ret.dir = (dir_t)dir;
|
ret.dir = (dir_t)dir;
|
||||||
ret.pos = uvector2(posx,posy);
|
ret.pos = uvector2(posx,posy);
|
||||||
|
@ -95,7 +91,6 @@ CUnit::CUnit()
|
||||||
: unit_id ( get_unique_unit_id() )
|
: unit_id ( get_unique_unit_id() )
|
||||||
, team_id ( Team::NUM_INVALID )
|
, team_id ( Team::NUM_INVALID )
|
||||||
, unit_vis ( unitVis_invalid )
|
, unit_vis ( unitVis_invalid )
|
||||||
, player_id ( player_id_invalid )
|
|
||||||
, dir ( dir_t::S )
|
, dir ( dir_t::S )
|
||||||
, pos ( { ucoord_invalid, ucoord_invalid } )
|
, pos ( { ucoord_invalid, ucoord_invalid } )
|
||||||
{
|
{
|
||||||
|
@ -106,7 +101,6 @@ CUnit::CUnit()
|
||||||
CUnit::CUnit(CUnit&& unit)
|
CUnit::CUnit(CUnit&& unit)
|
||||||
: unit_id ( std::move(unit.unit_id) )
|
: unit_id ( std::move(unit.unit_id) )
|
||||||
, team_id ( std::move(unit.team_id) )
|
, team_id ( std::move(unit.team_id) )
|
||||||
, player_id ( std::move(unit.player_id) )
|
|
||||||
, unit_vis ( std::move(unit.unit_vis) )
|
, unit_vis ( std::move(unit.unit_vis) )
|
||||||
, dir ( std::move(unit.dir) )
|
, dir ( std::move(unit.dir) )
|
||||||
, pos ( std::move(unit.pos) )
|
, pos ( std::move(unit.pos) )
|
||||||
|
@ -120,7 +114,6 @@ CUnit& CUnit::operator=(CUnit&& unit)
|
||||||
{
|
{
|
||||||
unit_id = std::move(unit.unit_id) ;
|
unit_id = std::move(unit.unit_id) ;
|
||||||
team_id = std::move(unit.team_id) ;
|
team_id = std::move(unit.team_id) ;
|
||||||
player_id = std::move(unit.player_id) ;
|
|
||||||
unit_vis = std::move(unit.unit_vis) ;
|
unit_vis = std::move(unit.unit_vis) ;
|
||||||
dir = std::move(unit.dir) ;
|
dir = std::move(unit.dir) ;
|
||||||
pos = std::move(unit.pos) ;
|
pos = std::move(unit.pos) ;
|
||||||
|
@ -132,7 +125,6 @@ bool CUnit::operator==(const CUnit& rhs)
|
||||||
{
|
{
|
||||||
return (unit_id == rhs.unit_id)
|
return (unit_id == rhs.unit_id)
|
||||||
&& (team_id == rhs.team_id)
|
&& (team_id == rhs.team_id)
|
||||||
&& (player_id == rhs.player_id)
|
|
||||||
&& (unit_vis == rhs.unit_vis)
|
&& (unit_vis == rhs.unit_vis)
|
||||||
&& (dir == rhs.dir)
|
&& (dir == rhs.dir)
|
||||||
&& (pos == rhs.pos);
|
&& (pos == rhs.pos);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "gametypes.h"
|
#include "gametypes.h"
|
||||||
#include "vector2.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
|
// Base unit type
|
||||||
class CUnit
|
class CUnit
|
||||||
|
@ -37,14 +37,12 @@ public:
|
||||||
// Getters for all the members
|
// Getters for all the members
|
||||||
inline const unit_id_t& getID() const { return unit_id; }
|
inline const unit_id_t& getID() const { return unit_id; }
|
||||||
inline const Team & getTeam() const { return team_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 unitVis_c& getVisual() const { return unit_vis; }
|
||||||
inline const dir_t& getDir() const { return dir; }
|
inline const dir_t& getDir() const { return dir; }
|
||||||
inline const uvector2& getPos() const { return pos; }
|
inline const uvector2& getPos() const { return pos; }
|
||||||
|
|
||||||
// Set
|
// Set
|
||||||
inline Team setTeam(const Team & v) { return (team_id = v); }
|
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 unitVis_c setVisual(const unitVis_c& v) { return ( unit_vis = v ); }
|
||||||
inline dir_t setDir(const dir_t& v) { return (dir = v); }
|
inline dir_t setDir(const dir_t& v) { return (dir = v); }
|
||||||
inline void setPos(const uvector2& v) { pos = v; }
|
inline void setPos(const uvector2& v) { pos = v; }
|
||||||
|
@ -77,9 +75,6 @@ private:
|
||||||
// Team ID
|
// Team ID
|
||||||
Team team_id;
|
Team team_id;
|
||||||
|
|
||||||
// Owner ID
|
|
||||||
player_id_t player_id;
|
|
||||||
|
|
||||||
// Direction
|
// Direction
|
||||||
dir_t dir;
|
dir_t dir;
|
||||||
|
|
||||||
|
@ -95,7 +90,6 @@ inline bool CUnit::valid() const
|
||||||
{
|
{
|
||||||
return (unit_id != unit_id_invalid )
|
return (unit_id != unit_id_invalid )
|
||||||
&& (team_id != Team::NUM_INVALID )
|
&& (team_id != Team::NUM_INVALID )
|
||||||
&& (player_id != player_id_invalid)
|
|
||||||
&& (unit_vis != unitVis_invalid);
|
&& (unit_vis != unitVis_invalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,10 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
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);
|
CUnit unit = CUnit::GetUnitFromVis(vis);
|
||||||
unit.setPos( vec );
|
unit.setPos( vec );
|
||||||
unit.setPlayer(player);
|
|
||||||
unit.setTeam(team);
|
unit.setTeam(team);
|
||||||
game.AddUnit(std::move(unit));
|
game.AddUnit(std::move(unit));
|
||||||
}
|
}
|
||||||
|
@ -27,17 +26,17 @@ int main()
|
||||||
CTTRTSGame game(21, 11);
|
CTTRTSGame game(21, 11);
|
||||||
game.SetName("Basic_5_v_5");
|
game.SetName("Basic_5_v_5");
|
||||||
|
|
||||||
AddUnitToGame(0, Team::Blue, '>', uvector2(1, 1), game);
|
AddUnitToGame( Team::Blue, '>', uvector2(1, 1), game);
|
||||||
AddUnitToGame(0, Team::Blue, '>', uvector2(1, 3), game);
|
AddUnitToGame( Team::Blue, '>', uvector2(1, 3), game);
|
||||||
AddUnitToGame(0, Team::Blue, '>', uvector2(1, 5), game);
|
AddUnitToGame( Team::Blue, '>', uvector2(1, 5), game);
|
||||||
AddUnitToGame(0, Team::Blue, '>', uvector2(1, 7), game);
|
AddUnitToGame( Team::Blue, '>', uvector2(1, 7), game);
|
||||||
AddUnitToGame(0, Team::Blue, '>', uvector2(1, 9), game);
|
AddUnitToGame( Team::Blue, '>', uvector2(1, 9), game);
|
||||||
|
|
||||||
AddUnitToGame(1, Team::Red, '<', uvector2(19, 1), game);
|
AddUnitToGame( Team::Red, '<', uvector2(19, 1), game);
|
||||||
AddUnitToGame(1, Team::Red, '<', uvector2(19, 3), game);
|
AddUnitToGame( Team::Red, '<', uvector2(19, 3), game);
|
||||||
AddUnitToGame(1, Team::Red, '<', uvector2(19, 5), game);
|
AddUnitToGame( Team::Red, '<', uvector2(19, 5), game);
|
||||||
AddUnitToGame(1, Team::Red, '<', uvector2(19, 7), game);
|
AddUnitToGame( Team::Red, '<', uvector2(19, 7), game);
|
||||||
AddUnitToGame(1, Team::Red, '<', uvector2(19, 9), game);
|
AddUnitToGame( Team::Red, '<', uvector2(19, 9), game);
|
||||||
|
|
||||||
OutputGame(game);
|
OutputGame(game);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ const char* tests()
|
||||||
{
|
{
|
||||||
CUnit unit1;
|
CUnit unit1;
|
||||||
unit1.setFromVisual('v');
|
unit1.setFromVisual('v');
|
||||||
unit1.setPlayer(0);
|
|
||||||
unit1.setTeam(Team::Green);
|
unit1.setTeam(Team::Green);
|
||||||
unit1.setPos( uvector2(5,10) );
|
unit1.setPos( uvector2(5,10) );
|
||||||
|
|
||||||
|
@ -84,7 +83,6 @@ const char* tests()
|
||||||
{
|
{
|
||||||
CUnit unit = CUnit::GetUnitFromVis('^');
|
CUnit unit = CUnit::GetUnitFromVis('^');
|
||||||
unit.setPos( {2,2} );
|
unit.setPos( {2,2} );
|
||||||
unit.setPlayer(0);
|
|
||||||
unit.setTeam(Team::Red);
|
unit.setTeam(Team::Red);
|
||||||
|
|
||||||
game.AddUnit(std::move(unit));
|
game.AddUnit(std::move(unit));
|
||||||
|
@ -93,7 +91,6 @@ const char* tests()
|
||||||
{
|
{
|
||||||
CUnit unit = CUnit::GetUnitFromVis('^');
|
CUnit unit = CUnit::GetUnitFromVis('^');
|
||||||
unit.setPos( {2,2} );
|
unit.setPos( {2,2} );
|
||||||
unit.setPlayer(0);
|
|
||||||
unit.setTeam(Team::Red);
|
unit.setTeam(Team::Red);
|
||||||
|
|
||||||
if( !game.AddUnit(std::move(unit)) )
|
if( !game.AddUnit(std::move(unit)) )
|
||||||
|
@ -113,7 +110,6 @@ const char* tests()
|
||||||
COrder order;
|
COrder order;
|
||||||
|
|
||||||
unit.setPos( {2,2} );
|
unit.setPos( {2,2} );
|
||||||
unit.setPlayer(0);
|
|
||||||
unit.setTeam(Team::Red);
|
unit.setTeam(Team::Red);
|
||||||
|
|
||||||
if ( game.AddUnit(std::move(unit)) )
|
if ( game.AddUnit(std::move(unit)) )
|
||||||
|
@ -122,7 +118,7 @@ const char* tests()
|
||||||
order.unit = id;
|
order.unit = id;
|
||||||
order.command = command_c::F;
|
order.command = command_c::F;
|
||||||
|
|
||||||
if( game.IssueOrder(0,order) )
|
if( game.IssueOrder(Team::Red,order) )
|
||||||
return "Game failed to issue valid order";
|
return "Game failed to issue valid order";
|
||||||
|
|
||||||
if (game.SimulateToNextTurn() )
|
if (game.SimulateToNextTurn() )
|
||||||
|
@ -145,7 +141,6 @@ const char* tests()
|
||||||
COrder order;
|
COrder order;
|
||||||
|
|
||||||
unit.setPos( {0,0} );
|
unit.setPos( {0,0} );
|
||||||
unit.setPlayer(1);
|
|
||||||
unit.setTeam(Team::Blue);
|
unit.setTeam(Team::Blue);
|
||||||
|
|
||||||
if ( game.AddUnit(std::move(unit)) )
|
if ( game.AddUnit(std::move(unit)) )
|
||||||
|
@ -154,14 +149,13 @@ const char* tests()
|
||||||
order.unit = id;
|
order.unit = id;
|
||||||
order.command = command_c::A;
|
order.command = command_c::A;
|
||||||
|
|
||||||
if( game.IssueOrder(0,order) )
|
if( game.IssueOrder(Team::Blue,order) )
|
||||||
return "Game failed to issue valid order";
|
return "Game failed to issue valid order";
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
CUnit unit = CUnit::GetUnitFromVis('<');
|
CUnit unit = CUnit::GetUnitFromVis('<');
|
||||||
|
|
||||||
unit.setPos( {1,0} );
|
unit.setPos( {1,0} );
|
||||||
unit.setPlayer(2);
|
|
||||||
unit.setTeam(Team::Red);
|
unit.setTeam(Team::Red);
|
||||||
|
|
||||||
if ( game.AddUnit(std::move(unit)) )
|
if ( game.AddUnit(std::move(unit)) )
|
||||||
|
|
Loading…
Add table
Reference in a new issue