Commit c65df947 authored by Jiakai Song's avatar Jiakai Song
Browse files

commit

parent d5c0daea
......@@ -2,10 +2,8 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="0cf971cc-497f-4c74-9aa1-f78fca398209" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/envs/soccer_against_keeper.py" beforeDir="false" afterPath="$PROJECT_DIR$/envs/soccer_against_keeper.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/envs/soccer_empty_goal.py" beforeDir="false" afterPath="$PROJECT_DIR$/envs/soccer_empty_goal.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/envs/soccer_env.py" beforeDir="false" afterPath="$PROJECT_DIR$/envs/soccer_env.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/envs/soccer_score_goal.py" beforeDir="false" afterPath="$PROJECT_DIR$/envs/soccer_score_goal.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -23,6 +21,7 @@
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
<component name="SvnConfiguration">
......@@ -39,6 +38,10 @@
<servers />
</component>
<component name="WindowStateProjectService">
<state x="1180" y="271" width="424" height="482" key="FileChooserDialogImpl" timestamp="1630564222384">
<screen x="65" y="24" width="1855" height="1056" />
</state>
<state x="1180" y="271" width="424" height="482" key="FileChooserDialogImpl/65.24.1855.1056@65.24.1855.1056" timestamp="1630564222384" />
<state x="485" y="174" key="SettingsEditor" timestamp="1630562526490">
<screen x="65" y="24" width="1855" height="1056" />
</state>
......
......@@ -18,9 +18,9 @@ class SoccerAgainstKeeperEnv(SoccerScoreGoalEnv):
"""
def __init__(self, sync=True, action_level='mid', offense_on_ball=False):
def __init__(self, sync=True, action_level='mid', use_shoot=True, offense_on_ball=False):
self.offense_on_ball = int(offense_on_ball)
super(SoccerAgainstKeeperEnv, self).__init__(sync, action_level)
super(SoccerAgainstKeeperEnv, self).__init__(sync, action_level, use_shoot)
def _configure_environment(self):
super(SoccerAgainstKeeperEnv, self)._start_hfo_server(defense_npcs=1,
......
......@@ -18,8 +18,8 @@ class SoccerEmptyGoalEnv(SoccerEnv):
the ball, kicks the ball towards the goal, and scores a goal.
"""
def __init__(self, sync=True, action_level='low'):
super(SoccerEmptyGoalEnv, self).__init__(sync, action_level)
def __init__(self, sync=True, action_level='low', use_shoot=False):
super(SoccerEmptyGoalEnv, self).__init__(sync, action_level, use_shoot)
self.old_ball_prox = 0
self.old_kickable = 0
self.old_ball_dist_goal = 0
......
......@@ -34,7 +34,7 @@ def find_free_port():
class SoccerEnv(gym.Env, utils.EzPickle):
metadata = {'render.modes': ['human']}
def __init__(self, sync=True, action_level='low'):
def __init__(self, sync=True, action_level='low', use_shoot=False):
self.sync = sync
self.viewer = None
self.server_process = None
......@@ -50,6 +50,7 @@ class SoccerEnv(gym.Env, utils.EzPickle):
# Action space omits the Tackle/Catch actions, which are useful on defense
assert action_level in ['low', 'mid']
self._action_level = action_level
self._use_shoot = use_shoot
if action_level == 'low':
low0 = np.array([0, -180], dtype=np.float32)
high0 = np.array([100, 180], dtype=np.float32)
......@@ -57,10 +58,6 @@ class SoccerEnv(gym.Env, utils.EzPickle):
high1 = np.array([180], dtype=np.float32)
low2 = np.array([0, -180], dtype=np.float32)
high2 = np.array([100, 180], dtype=np.float32)
self.action_space = spaces.Tuple((spaces.Discrete(3),
spaces.Box(low=low0, high=high0, dtype=np.float32),
spaces.Box(low=low1, high=high1, dtype=np.float32),
spaces.Box(low=low2, high=high2, dtype=np.float32)))
else:
low0 = np.array([-1, -1, 0], dtype=np.float32)
high0 = np.array([1, 1, 3], dtype=np.float32)
......@@ -68,14 +65,22 @@ class SoccerEnv(gym.Env, utils.EzPickle):
high1 = np.array([1, 1], dtype=np.float32)
low2 = np.array([-1, -1], dtype=np.float32)
high2 = np.array([1, 1], dtype=np.float32)
low3 = -1.0
high3 = 1.0
low3 = -1.0
high3 = 1.0
if use_shoot:
self.action_space = spaces.Tuple((spaces.Discrete(4),
spaces.Box(low=low0, high=high0, dtype=np.float32),
spaces.Box(low=low1, high=high1, dtype=np.float32),
spaces.Box(low=low2, high=high2, dtype=np.float32),
spaces.Box(low=low3, high=high3, dtype=np.float32, shape=(0,)),
))
else:
self.action_space = spaces.Tuple((spaces.Discrete(3),
spaces.Box(low=low0, high=high0, dtype=np.float32),
spaces.Box(low=low1, high=high1, dtype=np.float32),
spaces.Box(low=low2, high=high2, dtype=np.float32),
))
self.status = hfo_py.IN_GAME
self._seed = -1
......@@ -155,13 +160,17 @@ class SoccerEnv(gym.Env, utils.EzPickle):
self.viewer = subprocess.Popen(cmd.split(' '), shell=False)
def get_avail_actions(self):
avail_actions = np.ones([4]) if self._use_shoot else np.ones([3])
state = self.env.getState()
kickable = int(state[12]) == 1
if self._action_level == 'low':
avail_actions = np.ones([3])
if self._use_shoot and not kickable:
avail_actions[3] = 0
else:
avail_actions = np.ones([4])
state = self.env.getState()
if int(state[12]) != 1:
avail_actions[[0, 3]] = 0 # KICK_TO, SHOOT unavailable
if not kickable:
avail_actions[0] = 0
if self._use_shoot:
avail_actions[3] = 0
return avail_actions
def step(self, action):
......@@ -182,6 +191,8 @@ class SoccerEnv(gym.Env, utils.EzPickle):
self.env.act(action_type, action[3])
elif action_type == hfo_py.KICK:
self.env.act(action_type, action[4], action[5])
elif action_type == hfo_py.SHOOT:
self.env.act(action_type)
else:
print('Unrecognized action %d' % action_type)
self.env.act(hfo_py.NOOP)
......@@ -243,6 +254,7 @@ LOW_LEVEL_ACTION_LOOKUP = {
0: hfo_py.DASH,
1: hfo_py.TURN,
2: hfo_py.KICK,
3: hfo_py.SHOOT
}
MID_LEVEL_ACTION_LOOKUP = {
......
......@@ -23,8 +23,8 @@ class SoccerScoreGoalEnv(SoccerEmptyGoalEnv):
Action Spaces".
"""
def __init__(self, sync=True, action_level='low'):
super(SoccerScoreGoalEnv, self).__init__(sync, action_level)
def __init__(self, sync=True, action_level='low', use_shoot=False):
super(SoccerScoreGoalEnv, self).__init__(sync, action_level, use_shoot)
# dash, turn, kick, tackle
self.unum = self.env.getUnum() # uniform number (identifier) of our lone agent
print("UNUM =", self.unum)
......
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