Commit 07286e31 authored by Matthew Hausknecht's avatar Matthew Hausknecht

Updated python statusToString and actionToString as well as random_2v1.

parent b5249d39
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
# Before running this program, first Start HFO server: # Before running this program, first Start HFO server:
# $> ./bin/HFO --offense-agents 1 # $> ./bin/HFO --offense-agents 1
from __future__ import print_function
import argparse import argparse
import itertools import itertools
import random import random
...@@ -57,8 +59,9 @@ def main(): ...@@ -57,8 +59,9 @@ def main():
status = hfo_env.step() status = hfo_env.step()
# Check the outcome of the episode # Check the outcome of the episode
print(('Episode %d ended with %s'%(episode, end_status = hfo_env.statusToString(status)
hfo_env.statusToString(status)))) print("Episode {} ended with {}".format(episode, end_status))
# Quit if the server goes down # Quit if the server goes down
if status == hfo.SERVER_DOWN: if status == hfo.SERVER_DOWN:
hfo_env.act(hfo.QUIT) hfo_env.act(hfo.QUIT)
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
./bin/HFO --offense-agents=2 --defense-npcs=1 --trials 20 --headless & ./bin/HFO --offense-agents=2 --defense-npcs=1 --trials 20 --headless &
sleep 5 sleep 5
python2.7 -x example/high_level_random_agent.py --port 6000 &> agent1.txt & python -x example/high_level_random_agent.py --port 6000 &> agent1.txt &
sleep 5 sleep 5
python3 -x example/high_level_random_agent.py --port 6000 &> agent2.txt & python -x example/high_level_random_agent.py --port 6000 &> agent2.txt &
# The magic line # The magic line
# $$ holds the PID for this script # $$ holds the PID for this script
......
...@@ -29,6 +29,7 @@ LOW_LEVEL_FEATURE_SET, HIGH_LEVEL_FEATURE_SET = list(range(NUM_FEATURE_SETS)) ...@@ -29,6 +29,7 @@ LOW_LEVEL_FEATURE_SET, HIGH_LEVEL_FEATURE_SET = list(range(NUM_FEATURE_SETS))
NUM_HFO_ACTIONS = 19 NUM_HFO_ACTIONS = 19
DASH, TURN, TACKLE, KICK, KICK_TO, MOVE_TO, DRIBBLE_TO, INTERCEPT, \ 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 = 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"]
''' Possible game status ''' Possible game status
[IN_GAME] Game is currently active [IN_GAME] Game is currently active
...@@ -40,6 +41,7 @@ DASH, TURN, TACKLE, KICK, KICK_TO, MOVE_TO, DRIBBLE_TO, INTERCEPT, \ ...@@ -40,6 +41,7 @@ DASH, TURN, TACKLE, KICK, KICK_TO, MOVE_TO, DRIBBLE_TO, INTERCEPT, \
''' '''
NUM_GAME_STATUS_STATES = 6 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)) 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 ''' ''' Possible sides '''
RIGHT, NEUTRAL, LEFT = list(range(-1,2)) RIGHT, NEUTRAL, LEFT = list(range(-1,2))
...@@ -149,11 +151,11 @@ class HFOEnvironment(object): ...@@ -149,11 +151,11 @@ class HFOEnvironment(object):
def actionToString(self, action): def actionToString(self, action):
""" Returns a string representation of an action """ """ Returns a string representation of an action """
return hfo_lib.actionToString(action).decode('utf-8') return ACTION_STRINGS(action)
def statusToString(self, status): def statusToString(self, status):
""" Returns a string representation of a game status """ """ Returns a string representation of a game status """
return hfo_lib.statusToString(status).decode('utf-8') return STATUS_STRINGS[status]
def getUnum(self): def getUnum(self):
""" Return the uniform number of the agent """ """ Return the uniform number of the agent """
......
...@@ -40,13 +40,6 @@ extern "C" { ...@@ -40,13 +40,6 @@ extern "C" {
hfo::status_t step(hfo::HFOEnvironment *hfo) { return hfo->step(); } hfo::status_t step(hfo::HFOEnvironment *hfo) { return hfo->step(); }
int numParams(const hfo::action_t action) { return NumParams(action); } 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 getUnum(hfo::HFOEnvironment *hfo) {return hfo->getUnum();}
int getNumTeammates(hfo::HFOEnvironment *hfo) {return hfo->getNumTeammates();} int getNumTeammates(hfo::HFOEnvironment *hfo) {return hfo->getNumTeammates();}
int getNumOpponents(hfo::HFOEnvironment *hfo) {return hfo->getNumOpponents();} 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