Commit b9f7aa36 authored by drallensmith's avatar drallensmith

Bringing in from upstream/master

parents d21d0b1e c54d2350
sudo: required
language: cpp
dist: trusty
branches:
except:
- action_chart
addons:
apt:
sources:
......
......@@ -5,6 +5,8 @@ from __future__ import print_function
# Before running this program, first Start HFO server:
# $> ./bin/HFO --offense-agents 1
from __future__ import print_function
import argparse
import itertools
import random
......@@ -41,8 +43,10 @@ def main():
hfo_env.connectToServer(hfo.HIGH_LEVEL_FEATURE_SET,
'bin/teams/base/config/formations-dt', args.port,
'localhost', 'base_left', False)
if args.seed:
print("Python randomization seed: {0:d}".format(args.seed))
for episode in itertools.count():
status = hfo.IN_GAME
while status == hfo.IN_GAME:
......@@ -58,10 +62,12 @@ def main():
hfo_env.act(hfo.MOVE)
# Advance the environment and get the game status
status = hfo_env.step()
# Check the outcome of the episode
print("Episode {0:d} ended with {1:s}".format(episode,
hfo_env.statusToString(status)))
end_status = hfo_env.statusToString(status)
print("Episode {0:n} ended with {1:s}".format(episode, end_status))
# Quit if the server goes down
if status == hfo.SERVER_DOWN:
hfo_env.act(hfo.QUIT)
......
......@@ -2,10 +2,11 @@
./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 --port 6000 &> agent1.txt &
python ./example/high_level_custom_agent.py --port 6000 &> agent1.txt &
sleep 5
python3 -x ./example/high_level_custom_agent.py --port 6000 &> agent2.txt &
python ./example/high_level_custom_agent.py --port 6000 &> agent2.txt &
# The magic line
# $$ holds the PID for this script
......
......@@ -2,10 +2,12 @@
./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 --eps 0.2 --numTeammates=2 --numOpponents=3 --port 6000 &> agent1.txt &
# If wanting to test below with different python versions, add -x to avoid
# the #!/usr/bin/env python initial line.
python ./example/high_level_custom_agent.py --eps 0.2 --port 6000 &> agent1.txt &
sleep 5
python3 -x ./example/high_level_custom_agent.py --eps 0.2 --numTeammates=2 --numOpponents=3 --port 6000 &> agent2.txt &
python ./example/high_level_custom_agent.py --eps 0.2 --port 6000 &> agent2.txt &
# The magic line
# $$ holds the PID for this script
......
......@@ -2,9 +2,13 @@
./bin/HFO --offense-agents=2 --defense-npcs=1 --trials 20 --headless &
sleep 5
python2.7 -x example/high_level_random_agent.py --port 6000 &> agent1.txt &
# If wanting to test below with different python versions, add -x to avoid
# the #!/usr/bin/env python initial line.
python example/high_level_random_agent.py --port 6000 &> agent1.txt &
sleep 5
python3 -x example/high_level_random_agent.py --port 6000 &> agent2.txt &
python example/high_level_random_agent.py --port 6000 &> agent2.txt &
# The magic line
# $$ holds the PID for this script
......
......@@ -28,7 +28,8 @@ LOW_LEVEL_FEATURE_SET, HIGH_LEVEL_FEATURE_SET = list(range(NUM_FEATURE_SETS))
QUIT(): Quit the game '''
NUM_HFO_ACTIONS = 20
DASH, TURN, TACKLE, KICK, KICK_TO, MOVE_TO, DRIBBLE_TO, INTERCEPT, \
MOVE, SHOOT, PASS, DRIBBLE, CATCH, NOOP, QUIT, REDUCE_ANGLE_TO_GOAL,MARK_PLAYER,DEFEND_GOAL,GO_TO_BALL,REORIENT = list(range(NUM_HFO_ACTIONS))
MOVE, SHOOT, PASS, DRIBBLE, CATCH, NOOP, QUIT, REDUCE_ANGLE_TO_GOAL,MARK_PLAYER,DEFEND_GOAL,GO_TO_BALL = list(range(NUM_HFO_ACTIONS))
ACTION_STRINGS = ["Dash", "Turn", "Tackle", "Kick", "KickTo", "MoveTo", "DribbleTo", "Intercept", "Move", "Shoot", "Pass", "Dribble", "Catch", "No-op", "Quit", "Reduce_Angle_To_Goal", "Mark_Player", "Defend_Goal", "Go_To_Ball", "Reorient"]
''' Possible game status
[IN_GAME] Game is currently active
......@@ -40,6 +41,7 @@ DASH, TURN, TACKLE, KICK, KICK_TO, MOVE_TO, DRIBBLE_TO, INTERCEPT, \
'''
NUM_GAME_STATUS_STATES = 6
IN_GAME, GOAL, CAPTURED_BY_DEFENSE, OUT_OF_BOUNDS, OUT_OF_TIME, SERVER_DOWN = list(range(NUM_GAME_STATUS_STATES))
STATUS_STRINGS = ["InGame", "Goal", "CapturedByDefense", "OutOfBounds", "OutOfTime", "ServerDown"]
''' Possible sides '''
RIGHT, NEUTRAL, LEFT = list(range(-1,2))
......@@ -73,10 +75,6 @@ hfo_lib.step.argtypes = [c_void_p]
hfo_lib.step.restype = c_int
hfo_lib.numParams.argtypes = [c_int]
hfo_lib.numParams.restype = c_int
hfo_lib.actionToString.argtypes = [c_int]
hfo_lib.actionToString.restype = c_char_p
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]
......@@ -100,7 +98,7 @@ class HFOEnvironment(object):
play_goalie=False,
record_dir=''):
"""
Connect to the server on the specified port. The
Connects to the server on the specified port. The
following information is provided by the ./bin/HFO
feature_set: High or low level state features
......@@ -132,7 +130,7 @@ class HFOEnvironment(object):
hfo_lib.act(self.obj, action_type, params.ctypes.data_as(POINTER(c_float)))
def say(self, message):
""" Transmit a message """
""" Transmits a message """
hfo_lib.say(self.obj, message.encode('utf-8'))
def hear(self):
......@@ -149,14 +147,14 @@ class HFOEnvironment(object):
def actionToString(self, action):
""" Returns a string representation of an action """
return hfo_lib.actionToString(action).decode('utf-8')
return ACTION_STRINGS[action]
def statusToString(self, status):
""" Returns a string representation of a game status """
return hfo_lib.statusToString(status).decode('utf-8')
return STATUS_STRINGS[status]
def getUnum(self):
""" Return the uniform number of the agent """
""" Returns the uniform number of the agent """
return hfo_lib.getUnum(self.obj)
def getNumTeammates(self):
......
......@@ -40,13 +40,6 @@ extern "C" {
hfo::status_t step(hfo::HFOEnvironment *hfo) { return hfo->step(); }
int numParams(const hfo::action_t action) { return NumParams(action); }
const char* actionToString(const hfo::action_t action) {
return ActionToString(action).c_str();
}
const char* statusToString(const hfo::status_t status) {
StatusToString(status); // TODO: OSX requires two calls...?!
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();}
......
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