Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""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
return action
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
return action
state: Current state of the action being checked
"""
self._current_direction = football_action_set.action_idle
self._check_direction(football_action_set.action_top_left, top and
left)
self._check_direction(football_action_set.action_top_right, top and
right)
self._check_direction(football_action_set.action_bottom_left,
bottom and left)
self._check_direction(football_action_set.action_bottom_right,
bottom and right)
if self._current_direction == football_action_set.action_idle:
self._check_direction(football_action_set.action_right, right)
self._check_direction(football_action_set.action_left, left)
self._check_direction(football_action_set.action_top, top)
self._check_direction(football_action_set.action_bottom, bottom)
if self._current_direction != self._last_direction:
self._last_direction = self._current_direction
if self._current_direction == football_action_set.action_idle:
return football_action_set.action_release_direction
else:
return self._current_direction
self._last_action = football_action_set.action_idle
self._check_action(football_action_set.action_long_pass,
active_actions)
self._check_action(football_action_set.action_high_pass,
active_actions)
self._check_action(football_action_set.action_short_pass,
active_actions)
self._check_action(football_action_set.action_shot, active_actions)
self._check_action(football_action_set.action_keeper_rush,
active_actions)
def _direction_action(self, delta):
"""For required movement direction vector returns appropriate action."""
all_directions = [
football_action_set.action_top,
football_action_set.action_top_left,
football_action_set.action_left,
football_action_set.action_bottom_left,
football_action_set.action_bottom,
football_action_set.action_bottom_right,
football_action_set.action_right,
football_action_set.action_top_right
]
all_directions_vec = [(0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1),
(1, 0), (1, -1)]
all_directions_vec = [
np.array(v) / np.linalg.norm(np.array(v)) for v in all_directions_vec
]
best_direction = np.argmax([np.dot(delta, v) for v in all_directions_vec])
return all_directions[best_direction]