Commit 63c448e2 authored by drallensmith's avatar drallensmith

Add recording capabilities to two agents

parent fc943252
...@@ -62,26 +62,36 @@ def main(): ...@@ -62,26 +62,36 @@ def main():
help="Python randomization seed; uses python default if 0 or not given") help="Python randomization seed; uses python default if 0 or not given")
parser.add_argument('--rand-pass', action="store_true", parser.add_argument('--rand-pass', action="store_true",
help="Randomize order of checking teammates for a possible pass") help="Randomize order of checking teammates for a possible pass")
parser.add_argument('--eps', type=float, default=0, parser.add_argument('--epsilon', type=float, default=0,
help="Probability of a random action if has the ball, to adjust difficulty") help="Probability of a random action if has the ball, to adjust difficulty")
parser.add_argument('--record', action='store_true',
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('--numTeammates', type=int, default=0)
parser.add_argument('--numOpponents', type=int, default=1) parser.add_argument('--numOpponents', type=int, default=1)
args=parser.parse_args() args=parser.parse_args()
if args.seed: if args.seed:
random.seed(args.seed) random.seed(args.seed)
hfo_env = hfo.HFOEnvironment() hfo_env = hfo.HFOEnvironment()
if args.record:
hfo_env.connectToServer(hfo.HIGH_LEVEL_FEATURE_SET,
'bin/teams/base/config/formations-dt', args.port,
'localhost', 'base_left', False,
record_dir=args.rdir)
else:
hfo_env.connectToServer(hfo.HIGH_LEVEL_FEATURE_SET, hfo_env.connectToServer(hfo.HIGH_LEVEL_FEATURE_SET,
'bin/teams/base/config/formations-dt', args.port, 'bin/teams/base/config/formations-dt', args.port,
'localhost', 'base_left', False) 'localhost', 'base_left', False)
if args.seed: if args.seed:
if args.rand_pass or (args.eps > 0): if (args.rand_pass and (numTeammates > 1)) or (args.epsilon > 0):
print("Python randomization seed: {0:d}".format(args.seed)) print("Python randomization seed: {0:d}".format(args.seed))
else: else:
print("Python randomization seed setting is useless without --rand-pass or --eps >0") print("Python randomization seed useless without --rand-pass w/teammates or --epsilon >0")
if args.rand_pass and (args.numTeammates > 1): if args.rand_pass and (args.numTeammates > 1):
print("Randomizing order of checking for a pass") print("Randomizing order of checking for a pass")
if args.eps > 0: if args.epsilon > 0:
print("Using eps(ilon) {0:n}".format(args.eps)) print("Using epsilon {0:n}".format(args.epsilon))
for episode in itertools.count(): for episode in itertools.count():
num_eps = 0 num_eps = 0
num_had_ball = 0 num_had_ball = 0
...@@ -91,7 +101,7 @@ def main(): ...@@ -91,7 +101,7 @@ def main():
state = hfo_env.getState() state = hfo_env.getState()
#print(state) #print(state)
if int(state[5]) == 1: # state[5] is 1 when player has the ball if int(state[5]) == 1: # state[5] is 1 when player has the ball
if (args.eps > 0) and (random.random() < args.eps): if (args.epsilon > 0) and (random.random() < args.epsilon):
if random.random() < 0.5: if random.random() < 0.5:
hfo_env.act(hfo.SHOOT) hfo_env.act(hfo.SHOOT)
else: else:
...@@ -114,7 +124,7 @@ def main(): ...@@ -114,7 +124,7 @@ def main():
# Check the outcome of the episode # Check the outcome of the episode
print("Episode {0:d} ended with {1:s}".format(episode, print("Episode {0:d} ended with {1:s}".format(episode,
hfo_env.statusToString(status))) hfo_env.statusToString(status)))
if args.eps > 0: if args.epsilon > 0:
print("\tNum move: {0:d}; Random action: {1:d}; Nonrandom: {2:d}".format(num_move, print("\tNum move: {0:d}; Random action: {1:d}; Nonrandom: {2:d}".format(num_move,
num_eps, num_eps,
(num_had_ball- (num_had_ball-
......
...@@ -20,6 +20,10 @@ def main(): ...@@ -20,6 +20,10 @@ def main():
help="Server port") help="Server port")
parser.add_argument('--seed', type=int, default=None, parser.add_argument('--seed', type=int, default=None,
help="Python randomization seed; uses python default if 0 or not given") help="Python randomization seed; uses python default if 0 or not given")
parser.add_argument('--record', action='store_true',
help="Doing HFO --record")
parser.add_argument('--rdir', type=str, default='log/',
help="Set directory to use if doing HFO --record")
args=parser.parse_args() args=parser.parse_args()
if args.seed: if args.seed:
random.seed(args.seed) random.seed(args.seed)
...@@ -27,6 +31,12 @@ def main(): ...@@ -27,6 +31,12 @@ def main():
hfo_env = hfo.HFOEnvironment() hfo_env = hfo.HFOEnvironment()
# Connect to the server with the specified # Connect to the server with the specified
# feature set. See feature sets in hfo.py/hfo.hpp. # feature set. See feature sets in hfo.py/hfo.hpp.
if args.record:
hfo_env.connectToServer(hfo.HIGH_LEVEL_FEATURE_SET,
'bin/teams/base/config/formations-dt', args.port,
'localhost', 'base_left', False,
record_dir=args.rdir)
else:
hfo_env.connectToServer(hfo.HIGH_LEVEL_FEATURE_SET, hfo_env.connectToServer(hfo.HIGH_LEVEL_FEATURE_SET,
'bin/teams/base/config/formations-dt', args.port, 'bin/teams/base/config/formations-dt', args.port,
'localhost', 'base_left', False) 'localhost', 'base_left', False)
......
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