Commit 260c2416 authored by drallensmith's avatar drallensmith

Merge branch 'randomization' into add_preprocess_action - bring in improvements, avoid rebase

parents 3ec6cfef b06bf087
......@@ -68,8 +68,6 @@ def main():
help="If doing HFO --record")
parser.add_argument('--rdir', type=str, default='log/',
help="Set directory to use if doing --record")
parser.add_argument('--numTeammates', type=int, default=0)
parser.add_argument('--numOpponents', type=int, default=1)
args=parser.parse_args()
if args.seed:
random.seed(args.seed)
......@@ -83,12 +81,14 @@ def main():
hfo_env.connectToServer(hfo.HIGH_LEVEL_FEATURE_SET,
'bin/teams/base/config/formations-dt', args.port,
'localhost', 'base_left', False)
num_teammates = hfo_env.getNumTeammates()
#num_opponents = hfo_env.getNumOpponents()
if args.seed:
if (args.rand_pass and (args.numTeammates > 1)) or (args.epsilon > 0):
if (args.rand_pass and (num_teammates > 1)) or (args.epsilon > 0):
print("Python randomization seed: {0:d}".format(args.seed))
else:
print("Python randomization seed useless without --rand-pass w/teammates or --epsilon >0")
if args.rand_pass and (args.numTeammates > 1):
print("Python randomization seed useless without --rand-pass w/2+ teammates or --epsilon >0")
if args.rand_pass and (num_teammates > 1):
print("Randomizing order of checking for a pass")
if args.epsilon > 0:
print("Using epsilon {0:n}".format(args.epsilon))
......@@ -108,7 +108,7 @@ def main():
hfo_env.act(hfo.DRIBBLE)
num_eps += 1
else:
get_action(state,hfo_env,args.numTeammates,args.rand_pass)
get_action(state,hfo_env,num_teammates,args.rand_pass)
num_had_ball += 1
else:
hfo_env.act(hfo.MOVE)
......
......@@ -3,9 +3,9 @@
./bin/HFO --offense-agents=2 --defense-npcs=3 --offense-npcs=1 --trials 20 --headless &
sleep 5
# -x is needed to skip first line - otherwise whatever default python version is will run
python2.7 -x ./example/high_level_custom_agent.py --numTeammates=2 --numOpponents=3 --port 6000 &> agent1.txt &
python2.7 -x ./example/high_level_custom_agent.py --port 6000 &> agent1.txt &
sleep 5
python3 -x ./example/high_level_custom_agent.py --numTeammates=2 --numOpponents=3 --port 6000 &> agent2.txt &
python3 -x ./example/high_level_custom_agent.py --port 6000 &> agent2.txt &
# The magic line
# $$ holds the PID for this script
......
......@@ -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:
......@@ -339,10 +339,10 @@ Agent::ProcessTrainerMessages()
hfo::Config hfo_config;
if (hfo::ParseConfig(message, hfo_config)) {
bool playing_offense = world().ourSide() == rcsc::LEFT;
int num_teammates = playing_offense ?
hfo_config.num_offense - 1 : hfo_config.num_defense - 1;
int num_opponents = playing_offense ?
hfo_config.num_defense : hfo_config.num_offense;
num_teammates = playing_offense ?
hfo_config.num_offense - 1 : hfo_config.num_defense - 1;
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