<commit_before># Under MIT License, see LICENSE.txt
import time

import math

from Util import Pose
from Util.constant import IN_PLAY_MIN_DISTANCE, ROBOT_RADIUS
from Util.role import Role
from ai.Algorithm.evaluation_module import closest_players_to_point_except, \
    ball_going_toward_player
from ai.GameDomainObjects import Player
from ai.STA.Strategy.graphless_strategy import GraphlessStrategy
from ai.STA.Tactic.go_kick import GoKick
from ai.STA.Tactic.go_to_position import GoToPosition
from ai.STA.Tactic.goalkeeper import GoalKeeper
from ai.STA.Tactic.position_for_pass import PositionForPass
from ai.STA.Tactic.receive_pass import ReceivePass
from ai.STA.Tactic.tactic_constants import Flags

TIME_TO_GET_IN_POSITION = 5


# noinspection PyMethodMayBeStatic,PyMethodMayBeStatic
class GraphlessFreeKick(GraphlessStrategy):

    def __init__(self, p_game_state, can_kick_in_goal):
        super().__init__(p_game_state)

        self.robots_in_formation = [p for r, p in self.assigned_roles.items() if r != Role.GOALKEEPER]

        self.forbidden_areas = [self.game_state.field.free_kick_avoid_area,
                           self.game_state.field.our_goal_forbidden_area]

        initial_position_for_pass_center = {}
        for role, player in self.assigned_roles.items():
            if role == Role.GOALKEEPER:
                self.roles_to_tactics[role] = GoalKeeper(self.game_state, player)
            else:
                self.roles_to_tactics[role] = PositionForPass(self.game_state,
                                                              player,
                                                              robots_in_formation=self.robots_in_formation,
                                                              auto_position=True,
                                                              forbidden_areas=self.game_state.field.border_limits
                                                                              + self.forbidden_areas)

                initial_position_for_pass_center[role] = self.roles_to_tactics[role].area.center  # Hack

        # Find position for ball player closest to ball
        self.closest_role = None
        ball_position = self.game_state.ball_position
        for r, position in initial_position_for_pass_center.items():
            if self.closest_role is None \
                or (initial_position_for_pass_center[self.closest_role] -
                    ball_position).norm > (position - ball_position).norm:
                self.closest_role = r

        self.ball_start_position = self.game_state.ball.position
        self.next_state = self.get_in_position
        self.current_pass_receiver = None
        self.can_kick_in_goal = can_kick_in_goal
        self.first_passing_player = None

        self.start_time = time.time()

    def get_in_position(self):
        for role, player in self.assigned_roles.items():
            if role == Role.GOALKEEPER:
                continue
            if self.is_closest_not_goalkeeper(player):
                self.logger.info(f"Robot {player.id} is closest => go behind ball")
                self.first_passing_player = player

                their_goal_to_ball = self.game_state.ball_position - self.game_state.field.their_goal
                go_behind_position = self.game_state.ball_position + their_goal_to_ball.unit * ROBOT_RADIUS * 2.0
                go_behind_orientation = their_goal_to_ball.angle + math.pi
                self.roles_to_tactics[role] = GoToPosition(self.game_state,
                                                           player,
                                                           target=Pose(go_behind_position, go_behind_orientation))
            else:
                self.roles_to_tactics[role] = PositionForPass(self.game_state,
                                                              player,<commit_msg>Set GoToPosition cruise_speed to 1 in indirect free kick<commit_after># Under MIT License, see LICENSE.txt
import time

import math

from Util import Pose
from Util.constant import IN_PLAY_MIN_DISTANCE, ROBOT_RADIUS
from Util.role import Role
from ai.Algorithm.evaluation_module import closest_players_to_point_except, \
    ball_going_toward_player
from ai.GameDomainObjects import Player
from ai.STA.Strategy.graphless_strategy import GraphlessStrategy
from ai.STA.Tactic.go_kick import GoKick
from ai.STA.Tactic.go_to_position import GoToPosition
from ai.STA.Tactic.goalkeeper import GoalKeeper
from ai.STA.Tactic.position_for_pass import PositionForPass
from ai.STA.Tactic.receive_pass import ReceivePass
from ai.STA.Tactic.tactic_constants import Flags

TIME_TO_GET_IN_POSITION = 5


# noinspection PyMethodMayBeStatic,PyMethodMayBeStatic
class GraphlessFreeKick(GraphlessStrategy):

    def __init__(self, p_game_state, can_kick_in_goal):
        super().__init__(p_game_state)

        self.robots_in_formation = [p for r, p in self.assigned_roles.items() if r != Role.GOALKEEPER]

        self.forbidden_areas = [self.game_state.field.free_kick_avoid_area,
                           self.game_state.field.our_goal_forbidden_area]

        initial_position_for_pass_center = {}
        for role, player in self.assigned_roles.items():
            if role == Role.GOALKEEPER:
                self.roles_to_tactics[role] = GoalKeeper(self.game_state, player)
            else:
                self.roles_to_tactics[role] = PositionForPass(self.game_state,
                                                              player,
                                                              robots_in_formation=self.robots_in_formation,
                                                              auto_position=True,
                                                              forbidden_areas=self.game_state.field.border_limits
                                                                              + self.forbidden_areas)

                initial_position_for_pass_center[role] = self.roles_to_tactics[role].area.center  # Hack

        # Find position for ball player closest to ball
        self.closest_role = None
        ball_position = self.game_state.ball_position
        for r, position in initial_position_for_pass_center.items():
            if self.closest_role is None \
                or (initial_position_for_pass_center[self.closest_role] -
                    ball_position).norm > (position - ball_position).norm:
                self.closest_role = r

        self.ball_start_position = self.game_state.ball.position
        self.next_state = self.get_in_position
        self.current_pass_receiver = None
        self.can_kick_in_goal = can_kick_in_goal
        self.first_passing_player = None

        self.start_time = time.time()

    def get_in_position(self):
        for role, player in self.assigned_roles.items():
            if role == Role.GOALKEEPER:
                continue
            if self.is_closest_not_goalkeeper(player):
                self.logger.info(f"Robot {player.id} is closest => go behind ball")
                self.first_passing_player = player

                their_goal_to_ball = self.game_state.ball_position - self.game_state.field.their_goal
                go_behind_position = self.game_state.ball_position + their_goal_to_ball.unit * ROBOT_RADIUS * 2.0
                go_behind_orientation = their_goal_to_ball.angle + math.pi
                self.roles_to_tactics[role] = GoToPosition(self.game_state,
                                                           player,
                                                           target=Pose(go_behind_position, go_behind_orientation),
                                                           cruise_speed=1)
            else:
                self.roles_to_tactics[role] = PositionForPass(self.game_state,
                                                              player,
{'fraction_non_alphanumeric': 0.06181910311629085, 'fraction_numerical': 0.0010134279199391944, 'mean_word_length': 1.914359542266519, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2871868', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2107, 'n_words': 386}