Commit 357fe5ce authored by drallensmith's avatar drallensmith

Added functions to get number of teammates and number of opponents - no longer...

Added functions to get number of teammates and number of opponents - no longer have to specify for agents
parent 26d012e1
...@@ -79,6 +79,10 @@ hfo_lib.statusToString.argtypes = [c_int] ...@@ -79,6 +79,10 @@ hfo_lib.statusToString.argtypes = [c_int]
hfo_lib.statusToString.restype = c_char_p hfo_lib.statusToString.restype = c_char_p
hfo_lib.getUnum.argtypes = [c_void_p] hfo_lib.getUnum.argtypes = [c_void_p]
hfo_lib.getUnum.restype = c_int hfo_lib.getUnum.restype = c_int
hfo_lib.getNumTeammates.argtypes = [c_void_p]
hfo_lib.getNumTeammates.restype = c_int
hfo_lib.getNumOpponents.argtypes = [c_void_p]
hfo_lib.getNumOpponents.restype = c_int
class HFOEnvironment(object): class HFOEnvironment(object):
def __init__(self): def __init__(self):
...@@ -154,3 +158,11 @@ class HFOEnvironment(object): ...@@ -154,3 +158,11 @@ class HFOEnvironment(object):
def getUnum(self): def getUnum(self):
""" Return the uniform number of the agent """ """ Return the uniform number of the agent """
return hfo_lib.getUnum(self.obj) return hfo_lib.getUnum(self.obj)
def getNumTeammates(self):
""" Returns the number of teammates of the agent """
return hfo_lib.getNumTeammates(self.obj)
def getNumOpponents(self):
""" Returns the number of opponents of the agent """
return hfo_lib.getNumOpponents(self.obj)
...@@ -48,6 +48,8 @@ extern "C" { ...@@ -48,6 +48,8 @@ extern "C" {
return StatusToString(status).c_str(); return StatusToString(status).c_str();
} }
int getUnum(hfo::HFOEnvironment *hfo) {return hfo->getUnum();} int getUnum(hfo::HFOEnvironment *hfo) {return hfo->getUnum();}
int getNumTeammates(hfo::HFOEnvironment *hfo) {return hfo->getNumTeammates();}
int getNumOpponents(hfo::HFOEnvironment *hfo) {return hfo->getNumOpponents();}
} }
#endif #endif
...@@ -115,6 +115,14 @@ int HFOEnvironment::getUnum() { ...@@ -115,6 +115,14 @@ int HFOEnvironment::getUnum() {
return agent->getUnum(); return agent->getUnum();
} }
int HFOEnvironment::getNumTeammates() {
return agent->getNumTeammates();
}
int HFOEnvironment::getNumOpponents() {
return agent->getNumOpponents();
}
Player HFOEnvironment::playerOnBall() { Player HFOEnvironment::playerOnBall() {
return agent->getPlayerOnBall(); return agent->getPlayerOnBall();
} }
......
...@@ -49,6 +49,12 @@ class HFOEnvironment { ...@@ -49,6 +49,12 @@ class HFOEnvironment {
// Returns the uniform number of the player // Returns the uniform number of the player
virtual int getUnum(); virtual int getUnum();
// Returns the number of teammates
virtual int getNumTeammates();
// Returns the number of opponents
virtual int getNumOpponents();
// Get the current player holding the ball // Get the current player holding the ball
virtual Player playerOnBall(); virtual Player playerOnBall();
......
...@@ -212,16 +212,16 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) { ...@@ -212,16 +212,16 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) {
} }
FeatureExtractor* Agent::getFeatureExtractor(feature_set_t feature_set_indx, FeatureExtractor* Agent::getFeatureExtractor(feature_set_t feature_set_indx,
int num_teammates, int numTeammates,
int num_opponents, int numOpponents,
bool playing_offense) { bool playing_offense) {
switch (feature_set_indx) { switch (feature_set_indx) {
case LOW_LEVEL_FEATURE_SET: case LOW_LEVEL_FEATURE_SET:
return new LowLevelFeatureExtractor(num_teammates, num_opponents, return new LowLevelFeatureExtractor(numTeammates, numOpponents,
playing_offense); playing_offense);
break; break;
case HIGH_LEVEL_FEATURE_SET: case HIGH_LEVEL_FEATURE_SET:
return new HighLevelFeatureExtractor(num_teammates, num_opponents, return new HighLevelFeatureExtractor(numTeammates, numOpponents,
playing_offense); playing_offense);
break; break;
default: default:
...@@ -336,10 +336,10 @@ Agent::ProcessTrainerMessages() ...@@ -336,10 +336,10 @@ Agent::ProcessTrainerMessages()
hfo::Config hfo_config; hfo::Config hfo_config;
if (hfo::ParseConfig(message, hfo_config)) { if (hfo::ParseConfig(message, hfo_config)) {
bool playing_offense = world().ourSide() == rcsc::LEFT; bool playing_offense = world().ourSide() == rcsc::LEFT;
int num_teammates = playing_offense ? num_teammates = playing_offense ?
hfo_config.num_offense - 1 : hfo_config.num_defense - 1; hfo_config.num_offense - 1 : hfo_config.num_defense - 1;
int num_opponents = playing_offense ? num_opponents = playing_offense ?
hfo_config.num_defense : hfo_config.num_offense; hfo_config.num_defense : hfo_config.num_offense;
feature_extractor = getFeatureExtractor( feature_extractor = getFeatureExtractor(
feature_set, num_teammates, num_opponents, playing_offense); feature_set, num_teammates, num_opponents, playing_offense);
} }
......
...@@ -61,6 +61,8 @@ protected: ...@@ -61,6 +61,8 @@ protected:
std::string say_msg, hear_msg; // Messages to/from teammates std::string say_msg, hear_msg; // Messages to/from teammates
hfo::action_t requested_action; // Currently requested action hfo::action_t requested_action; // Currently requested action
std::vector<float> params; // Parameters of current action std::vector<float> params; // Parameters of current action
int num_teammates; // Number of teammates
int num_opponents; // Number of opponents
public: public:
inline const std::vector<float>& getState() { return state; } inline const std::vector<float>& getState() { return state; }
...@@ -68,6 +70,8 @@ protected: ...@@ -68,6 +70,8 @@ protected:
inline const hfo::Player& getPlayerOnBall() { return player_on_ball; } inline const hfo::Player& getPlayerOnBall() { return player_on_ball; }
inline const std::string& getHearMsg() { return hear_msg; } inline const std::string& getHearMsg() { return hear_msg; }
int getUnum(); // Returns the uniform number of the player int getUnum(); // Returns the uniform number of the player
inline int getNumTeammates() { return num_teammates; }
inline int getNumOpponents() { return num_opponents; }
inline void setFeatureSet(hfo::feature_set_t fset) { feature_set = fset; } inline void setFeatureSet(hfo::feature_set_t fset) { feature_set = fset; }
inline std::vector<float>* mutable_params() { return &params; } inline std::vector<float>* mutable_params() { return &params; }
......
...@@ -53,6 +53,12 @@ def test_with_server(): ...@@ -53,6 +53,12 @@ def test_with_server():
print("My unum is {!s}".format(my_unum)) print("My unum is {!s}".format(my_unum))
num_teammates = hfo_env.getNumTeammates()
assert (num_teammates == 2), "Wrong num teammates ({!r})".format(num_teammates)
num_opponents = hfo_env.getNumOpponents()
assert (num_opponents == 2), "Wrong num opponents ({!r})".format(num_opponents)
had_ok_unum = False had_ok_unum = False
had_ok_unum_set_my_side = set() had_ok_unum_set_my_side = set()
had_ok_unum_set_their_side = set(); had_ok_unum_set_their_side = set();
......
...@@ -54,6 +54,12 @@ def test_with_server(): ...@@ -54,6 +54,12 @@ def test_with_server():
print("My unum is {!s}".format(my_unum)) print("My unum is {!s}".format(my_unum))
num_teammates = hfo_env.getNumTeammates()
assert (num_teammates == 2), "Wrong num teammates ({!r})".format(num_teammates)
num_opponents = hfo_env.getNumOpponents()
assert (num_opponents == 2), "Wrong num opponents ({!r})".format(num_opponents)
had_ok_unum = False had_ok_unum = False
had_ok_unum_set_my_side = set() had_ok_unum_set_my_side = set()
had_ok_unum_set_their_side = set(); had_ok_unum_set_their_side = set();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment