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:
return football_action_set.action_top_right
# Info about direction
players_info[(team, player_idx)]['DIRECTION'] = \
'O' if active_direction is None else active_direction._name
if 'action' in o._trace['debug']:
# Info about action
players_info[(team, player_idx)]['ACTION'] = \
o['action'][player]._name
write_players_state(writer, players_info)
if 'baseline' in o._trace['debug']:
writer.write('BASELINE: %.5f' % o._trace['debug']['baseline'])
if 'logits' in o._trace['debug']:
probs = softmax(o._trace['debug']['logits'])
action_set = football_action_set.get_action_set(self._config)
for action, prob in zip(action_set, probs):
writer.write('%s: %.5f' % (action.name, prob), scale_factor=0.5)
for d in o._debugs:
writer.write(d)
self._video_writer.write(frame)
# Write the dump.
temp_frame = None
if 'frame' in o._trace['observation']:
temp_frame = o._trace['observation']['frame']
del o._trace['observation']['frame']
# Add config to the first frame for our replay tools to use.
if self._step_cnt == 0:
o['debug']['config'] = self._config.get_dictionary()
six.moves.cPickle.dump(o._trace, self._dump_file)
def __init__(self, config):
self._config = config
player_config = {'index': 0}
# There can be at most one agent at a time. We need to remember its
# team and the index on the team to generate observations appropriately.
self._agent = None
self._agent_index = -1
self._agent_left_position = -1
self._agent_right_position = -1
self._players = self._construct_players(config['players'], player_config)
self._env = football_env_core.FootballEnvCore(self._config)
self._num_actions = len(football_action_set.get_action_set(self._config))
self._cached_observation = None
def reset(self, inc=1):
"""Reset environment for a new episode using a given config."""
self._episode_start = timeit.default_timer()
self._action_set = football_action_set.get_action_set(self._config)
trace = observation_processor.ObservationProcessor(self._config)
self._cumulative_reward = 0
self._step_count = 0
self._trace = trace
self._reset(self._env.game_config.render, inc=inc)
while not self._retrieve_observation():
self._env.step()
return True