Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def rotate_sticky_actions(sticky_actions_state, config):
"""Rotate the sticky bits of directional actions.
This is used to make a policy believe it is playing from left to right
although it is actually playing from right to left.
Args:
sticky_actions_state: Array of bits corresponding to the active actions.
config: config used by the environment
Returns:
Array of bits corresponding to the same active actions for a player
who would play from the opposite side.
"""
sticky_actions = football_action_set.get_sticky_actions(config)
assert len(sticky_actions) == len(sticky_actions_state), len(sticky_actions)
action_to_state = {}
for i in range(len(sticky_actions)):
action_to_state[sticky_actions[i]] = sticky_actions_state[i]
rotated_sticky_actions = []
for i in range(len(sticky_actions)):
rotated_sticky_actions.append(action_to_state[flip_single_action(
sticky_actions[i], config)])
return rotated_sticky_actions
def __init__(self, config):
global _unused_engines
self._config = config
self._sticky_actions = football_action_set.get_sticky_actions(config)
self._use_rendering_engine = False
if _unused_engines:
self._env = _unused_engines.pop()
else:
self._env = libgame.GameEnv()
self._env.game_config.physics_steps_per_frame = config['physics_steps_per_frame']
# Reset is needed here to make sure render() API call before reset() API
# call works fine (get/setState makes sure env. config is the same).
self.reset(inc=0)
frame = frame[..., ::-1]
frame = cv2.resize(frame, self._frame_dim, interpolation=cv2.INTER_AREA)
writer = TextWriter(frame, self._frame_dim[0] - 300)
if self._config['custom_display_stats']:
for line in self._config['custom_display_stats']:
writer.write(line)
if self._config['display_game_stats']:
writer.write('SCORE: %d - %d' % (o['score'][0], o['score'][1]))
writer.write('BALL OWNED TEAM: %d' % (o['ball_owned_team']))
writer.write('BALL OWNED PLAYER: %d' % (o['ball_owned_player']))
writer.write('REWARD %.4f' % (o['reward']))
writer.write('CUM. REWARD: %.4f' % (o['cumulative_reward']))
writer = TextWriter(frame, 0)
writer.write('FRAME: %d' % self._step_cnt)
writer.write('TIME: %f' % (o._time - self._last_frame_time))
sticky_actions = football_action_set.get_sticky_actions(self._config)
players_info = {}
for team in ['left', 'right']:
sticky_actions_field = '%s_agent_sticky_actions' % team
for player in range(len(o[sticky_actions_field])):
assert len(sticky_actions) == len(o[sticky_actions_field][player])
player_idx = o['%s_agent_controlled_player' % team][player]
players_info[(team, player_idx)] = {}
players_info[(team, player_idx)]['color'] = (
0, 255, 0) if team == 'left' else (0, 255, 255)
players_info[(team, player_idx)]['id'] = 'G' if o[
'%s_team_roles' %
team][player_idx] == e_PlayerRole_GK else str(player_idx)
active_direction = None
for i in range(len(sticky_actions)):
if sticky_actions[i]._directional: