Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def flip_single_action(action, config):
"""Actions corresponding to the field rotated by 180 degrees."""
action = football_action_set.named_action_from_action_set(
football_action_set.get_action_set(config), action)
if action == football_action_set.action_left:
return football_action_set.action_right
if action == football_action_set.action_top_left:
return football_action_set.action_bottom_right
if action == football_action_set.action_top:
return football_action_set.action_bottom
if action == football_action_set.action_top_right:
return football_action_set.action_bottom_left
if action == football_action_set.action_right:
return football_action_set.action_left
if action == football_action_set.action_bottom_right:
return football_action_set.action_top_left
if action == football_action_set.action_bottom:
return football_action_set.action_top
if action == football_action_set.action_bottom_left:
def step(self, action, extra_data={}):
assert self._env.state != GameState.game_done, (
'Cant call step() once episode finished (call reset() instead)')
assert self._env.state == GameState.game_running, (
'reset() must be called before step()')
action = [
football_action_set.named_action_from_action_set(self._action_set, a)
for a in action
]
self._step_count += 1
# If agent 'holds' the game for too long, just start it.
if self._env.waiting_for_game_count > 20:
self._env.waiting_for_game_count = 0
action = [football_action_set.action_short_pass] * (
self._env.config.left_agents + self._env.config.right_agents)
assert len(action) == (
self._env.config.left_agents + self._env.config.right_agents)
debug = {}
debug['action'] = action
action_index = 0
for i in range(self._env.config.left_agents):
player_action = action[action_index]
def step(self, action, extra_data={}):
if self._env_state != 'game_started':
raise RuntimeError('invalid game state: {}'.format(self._env_state))
action = [
football_action_set.named_action_from_action_set(self._action_set, a)
for a in action
]
self._step_count += 1
observation, reward, done, debug = self._env.step(action)
debug['time'] = timeit.default_timer()
debug.update(extra_data)
self._cumulative_reward += reward
single_observation = copy.deepcopy(observation)
trace = {
'debug': debug,
'observation': single_observation,
'reward': reward,
'cumulative_reward': self._cumulative_reward
}
self._trace.update(trace)
if done: