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]
hfo_lib.statusToString.restype = c_char_p
hfo_lib.getUnum.argtypes = [c_void_p]
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):
def __init__(self):
......@@ -154,3 +158,11 @@ class HFOEnvironment(object):
def getUnum(self):
""" Return the uniform number of the agent """
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" {
return StatusToString(status).c_str();
}
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
......@@ -115,6 +115,14 @@ int HFOEnvironment::getUnum() {
return agent->getUnum();
}
int HFOEnvironment::getNumTeammates() {
return agent->getNumTeammates();
}
int HFOEnvironment::getNumOpponents() {
return agent->getNumOpponents();
}
Player HFOEnvironment::playerOnBall() {
return agent->getPlayerOnBall();
}
......
......@@ -49,6 +49,12 @@ class HFOEnvironment {
// Returns the uniform number of the player
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
virtual Player playerOnBall();
......
......@@ -212,16 +212,16 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) {
}
FeatureExtractor* Agent::getFeatureExtractor(feature_set_t feature_set_indx,
int num_teammates,
int num_opponents,
int numTeammates,
int numOpponents,
bool playing_offense) {
switch (feature_set_indx) {
case LOW_LEVEL_FEATURE_SET:
return new LowLevelFeatureExtractor(num_teammates, num_opponents,
return new LowLevelFeatureExtractor(numTeammates, numOpponents,
playing_offense);
break;
case HIGH_LEVEL_FEATURE_SET:
return new HighLevelFeatureExtractor(num_teammates, num_opponents,
return new HighLevelFeatureExtractor(numTeammates, numOpponents,
playing_offense);
break;
default:
......@@ -336,9 +336,9 @@ Agent::ProcessTrainerMessages()
hfo::Config hfo_config;
if (hfo::ParseConfig(message, hfo_config)) {
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;
int num_opponents = playing_offense ?
num_opponents = playing_offense ?
hfo_config.num_defense : hfo_config.num_offense;
feature_extractor = getFeatureExtractor(
feature_set, num_teammates, num_opponents, playing_offense);
......
......@@ -61,6 +61,8 @@ protected:
std::string say_msg, hear_msg; // Messages to/from teammates
hfo::action_t requested_action; // Currently requested action
std::vector<float> params; // Parameters of current action
int num_teammates; // Number of teammates
int num_opponents; // Number of opponents
public:
inline const std::vector<float>& getState() { return state; }
......@@ -68,6 +70,8 @@ protected:
inline const hfo::Player& getPlayerOnBall() { return player_on_ball; }
inline const std::string& getHearMsg() { return hear_msg; }
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 std::vector<float>* mutable_params() { return &params; }
......
......@@ -53,6 +53,12 @@ def test_with_server():
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_set_my_side = set()
had_ok_unum_set_their_side = set();
......
......@@ -54,6 +54,12 @@ def test_with_server():
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_set_my_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