def exec(self): self.define_center_of_formation() self.compute_positions_in_formation() # print(self.player_number_in_formation) for idx, player in enumerate(self.robots_in_formation): if not self.is_not_one_of_the_closests(player): self.get_players_in_formation() self.define_center_of_formation() self.compute_positions_in_formation() break # print(self.robots_in_formation) # print(self.player_number_in_formation) # print(self.player.id) if self.check_success(): return self.halt else: destination_orientation = ( self.ball_position - self.positions_in_formations[self.player_number_in_formation] ).angle() return GoToPositionPathfinder( self.game_state, self.player, Pose( self.positions_in_formations[ self.player_number_in_formation], destination_orientation)).exec()
def stay_out_of_circle(self): self.game_state.field.field_collision_body.append( CollisionBody(self.game_state.get_ball_position(), self.game_state.get_ball_velocity(), 500)) position = stayOutsideCircle(self.player.pose.position, self.game_state.get_ball_position(), self.keepout_radius) return GoToPositionPathfinder(self.game_state, self.player, Pose(position, self.player.pose.orientation))
def __init__(self, p_game_state): super().__init__(p_game_state) # Attribution des joueurs attack_top = self.game_state.get_player_by_role(Role.FIRST_ATTACK) attack_bottom = self.game_state.get_player_by_role(Role.SECOND_ATTACK) middle = self.game_state.get_player_by_role(Role.MIDDLE) defense_top = self.game_state.get_player_by_role(Role.FIRST_DEFENCE) defense_bottom = self.game_state.get_player_by_role( Role.SECOND_DEFENCE) goalkeeper = self.game_state.get_player_by_role(Role.GOALKEEPER) center_offset = GameState().const["CENTER_CENTER_RADIUS"] if GameState().const["FIELD_OUR_GOAL_X_EXTERNAL"]>0 \ else -GameState().const["CENTER_CENTER_RADIUS"] # Positions objectifs des joueurs attack_top_position = Pose( GameState().const["FIELD_OUR_GOAL_X_EXTERNAL"] / 10, GameState().const["FIELD_Y_BOTTOM"] * 3 / 5, 0) attack_bottom_position = Pose( GameState().const["FIELD_OUR_GOAL_X_EXTERNAL"] / 10, GameState().const["FIELD_Y_TOP"] * 3 / 5, 0) middle_position = Pose( center_offset + GameState().const["FIELD_OUR_GOAL_X_EXTERNAL"] / 10, 0, 0) defense_top_position = Pose( GameState().const["FIELD_OUR_GOAL_X_EXTERNAL"] / 2, GameState().const["FIELD_Y_TOP"] / 10, 0) defense_bottom_position = Pose( GameState().const["FIELD_OUR_GOAL_X_EXTERNAL"] / 2, GameState().const["FIELD_Y_BOTTOM"] / 10, 0) our_goal = Pose(GameState().const["FIELD_OUR_GOAL_X_EXTERNAL"], 0, 0) self.add_tactic(Role.GOALKEEPER, GoalKeeper(self.game_state, goalkeeper, our_goal)) robots_and_positions = [(attack_top, attack_top_position), (attack_bottom, attack_bottom_position), (middle, middle_position), (defense_top, defense_top_position), (defense_bottom, defense_bottom_position)] for player, position in robots_and_positions: if player: role = GameState().get_role_by_player_id(player.id) self.add_tactic( role, GoToPositionPathfinder(self.game_state, player, position)) self.add_tactic(role, Stop(self.game_state, player)) self.add_condition(role, 0, 1, partial(self.arrived_to_position, player))
def __init__(self, p_game_state): super().__init__(p_game_state) ourgoal = Pose(Position(GameState().const["FIELD_OUR_GOAL_X_EXTERNAL"], 0), 0) self.theirgoal = Pose(Position(GameState().const["FIELD_THEIR_GOAL_X_EXTERNAL"], 0), 0) roles_in_waiting_line = [Role.SECOND_ATTACK, Role.MIDDLE, Role.FIRST_DEFENCE, Role.SECOND_DEFENCE] position_list = [Pose(Position(ourgoal.position.x / 8, GameState().const["FIELD_Y_TOP"] * 2 / 3)), Pose(Position(ourgoal.position.x / 8, GameState().const["FIELD_Y_TOP"] / 3)), Pose(Position(ourgoal.position.x / 8, GameState().const["FIELD_Y_BOTTOM"] / 3)), Pose(Position(ourgoal.position.x / 8, GameState().const["FIELD_Y_BOTTOM"] * 2 / 3))] postions_for_roles = dict(zip(roles_in_waiting_line, position_list)) goalkeeper = self.game_state.get_player_by_role(Role.GOALKEEPER) self.add_tactic(Role.GOALKEEPER, GoToPositionPathfinder(self.game_state, goalkeeper, ourgoal)) kicker = self.game_state.get_player_by_role(Role.FIRST_ATTACK) self.add_tactic(Role.FIRST_ATTACK, GoKick(self.game_state, kicker, self.theirgoal)) for role in roles_in_waiting_line: position = postions_for_roles[role] player = self.game_state.get_player_by_role(role) if player: self.add_tactic(role, GoToPositionPathfinder(self.game_state, player, position))
def exec(self): if self.check_success(): self.current_position_index_to_go = random.randint( 0, len(self.grid_of_positions) - 1) self.current_position_to_go = self.grid_of_positions[ self.current_position_index_to_go] #self.current_angle_to_go = random.randint(-1, 1) * np.pi / 100. self.next_pose = Pose(self.current_position_to_go, self.current_angle_to_go) self.next_state = self.exec return GoToPositionPathfinder(self.game_state, self.player, self.next_pose).exec()
def grab_ball(self): distance_to_kick = KICK_DISTANCE + self.grab_ball_tries * 10 ball_position = self.game_state.get_ball_position() distance_behind = self.get_destination_behind_ball(GRAB_BALL_SPACING) orientation = (self.target.position - ball_position).angle() if self._get_distance_from_ball() < distance_to_kick: self.next_state = self.kick return GoToPositionPathfinder(self.game_state, self.player, Pose(distance_behind, orientation), cruise_speed=2, charge_kick=True, end_speed=0.2, collision_ball=False)
def exec(self): """ Calcul la pose que doit prendre le gardien en fonction de la position de la balle. :return: Un tuple (Pose, kick) où Pose est la destination du gardien et kick est nul (on ne botte pas) """ goalkeeper_position = self.player.pose.position ball_position = self.game_state.get_ball_position() goal_x = self.game_state.const["FIELD_OUR_GOAL_X_EXTERNAL"] goal_position = Position(goal_x, 0) # Calcul des deux positions extremums entre la balle et le centre du but inner_circle_position = stayInsideCircle(ball_position, goal_position, self.minimum_distance) outer_circle_position = stayInsideCircle(ball_position, goal_position, self.maximum_distance) destination_position = get_closest_point_on_segment( goalkeeper_position, inner_circle_position, outer_circle_position) # Vérification que destination_position respecte la distance maximale if self.maximum_distance is None: destination_position = self.game_state.game.field.stay_inside_goal_area( destination_position, our_goal=True) else: destination_position = stayInsideCircle(destination_position, goal_position, self.maximum_distance) # Calcul de l'orientation de la pose de destination #destination_orientation = (ball_position - destination_position).angle() destination_pose = Pose(destination_position, self.player.pose.orientation) # return AICommand(self.player, # AICommandType.MOVE, # pose_goal=destination_pose, # pathfinder_on=False) return GoToPositionPathfinder(self.game_state, self.player, destination_pose, end_speed=0.5).exec()
def go_behind_ball(self): self.ball_spacing = GRAB_BALL_SPACING self.status_flag = Flags.WIP ball_position = self.game_state.get_ball_position() orientation = (self.target.position - ball_position).angle() distance_behind = self.get_destination_behind_ball(GRAB_BALL_SPACING * 3) if (self.player.pose.position - distance_behind).norm() < 100 and abs( orientation - self.player.pose.orientation) < 0.1: self.next_state = self.grab_ball else: self.next_state = self.go_behind_ball if self.auto_update_target: self._find_best_passing_option() collision_ball = self.tries_flag == 0 return GoToPositionPathfinder(self.game_state, self.player, Pose(distance_behind, orientation), collision_ball=True, cruise_speed=2, end_speed=0.2)
def grab_ball(self): if self._is_ball_too_far(): self.next_state = self.protect_goal if self.grab_ball_tries == 0: if self._get_distance_from_ball() < KICK_DISTANCE: self.next_state = self.kick else: if self._get_distance_from_ball() < (KICK_DISTANCE + self.grab_ball_tries * 10): self.next_state = self.kick ball_position = self.game_state.get_ball_position() orientation = (self.target.position - ball_position).angle() distance_behind = self.get_destination_behind_ball(GRAB_BALL_SPACING) return GoToPositionPathfinder(self.game_state, self.player, Pose(distance_behind, orientation), cruise_speed=2, charge_kick=True, end_speed=0.3, collision_ball=False)
def __init__(self, game_state, hard_code=True): super().__init__(game_state) # ID Robot Indiana Jones : 0 # ID Robot obstacles mouvants : 1 et 2 if hard_code: game_state.map_players_to_roles_by_player_id({ Role.FIRST_DEFENCE: 3, Role.MIDDLE: 4, Role.SECOND_DEFENCE: 6, }) indiana = self.game_state.get_player_by_role(Role.MIDDLE) indiana_role = Role.MIDDLE obs_right = self.game_state.get_player_by_role(Role.FIRST_DEFENCE) obs_right_role = Role.FIRST_DEFENCE obs_left = self.game_state.get_player_by_role(Role.SECOND_DEFENCE) obs_left_role = Role.SECOND_DEFENCE # TODO: The position must be update to fit to the current field # Positions objectifs d'Indiana Jones goal_left = (Pose( Position(self.game_state.const["FIELD_OUR_GOAL_X_INTERNAL"], 0), self.game_state.get_player_by_role(indiana_role).pose.orientation)) goal_right = (Pose( Position(self.game_state.const["FIELD_THEIR_GOAL_X_INTERNAL"], 0), self.game_state.get_player_by_role(indiana_role).pose.orientation)) # Positions objectifs des obstacles y_down = self.game_state.const["FIELD_Y_BOTTOM"] + 500 y_top = self.game_state.const["FIELD_Y_TOP"] - 500 x_left = self.game_state.const["FIELD_X_LEFT"] + 500 x_right = self.game_state.const["FIELD_X_RIGHT"] - 500 self.add_tactic( indiana_role, GoToPositionPathfinder(self.game_state, indiana, goal_left, cruise_speed=2)) self.add_tactic( indiana_role, GoToPositionPathfinder(self.game_state, indiana, goal_right, cruise_speed=2)) self.add_condition(indiana_role, 0, 1, partial(self.condition, indiana_role)) self.add_condition(indiana_role, 1, 0, partial(self.condition, indiana_role)) self.add_tactic( obs_left_role, GoToPositionPathfinder(self.game_state, obs_left, Pose( Position(x_left / 2, y_top), self.game_state.get_player_by_role( obs_left_role).pose.orientation), cruise_speed=2)) self.add_tactic( obs_left_role, GoToPositionPathfinder( self.game_state, obs_left, Pose( Position(x_left / 2, y_down), self.game_state.get_player_by_role( obs_left_role).pose.orientation))) self.add_condition(obs_left_role, 0, 1, partial(self.condition, obs_left_role)) self.add_condition(obs_left_role, 1, 0, partial(self.condition, obs_left_role)) self.add_tactic( obs_right_role, GoToPositionPathfinder(self.game_state, obs_right, Pose( Position(x_right / 2, y_top), self.game_state.get_player_by_role( obs_right_role).pose.orientation), cruise_speed=2)) self.add_tactic( obs_right_role, GoToPositionPathfinder(self.game_state, obs_right, Pose( Position(x_right / 2, y_down), self.game_state.get_player_by_role( obs_right_role).pose.orientation), cruise_speed=2)) self.add_condition(obs_right_role, 0, 1, partial(self.condition, obs_right_role)) self.add_condition(obs_right_role, 1, 0, partial(self.condition, obs_right_role))
def move_to_pass_position(self): self.next_state = self.move_to_pass_position return GoToPositionPathfinder(self.game_state, self.player, self._get_destination_pose())
def __init__(self, p_game_state): super().__init__(p_game_state) robot1 = Role.FIRST_ATTACK robot2 = Role.SECOND_ATTACK robot3 = Role.MIDDLE self.tactic_conditions = [False for i in range(PLAYER_PER_TEAM)] dist_inter_robot = 300 positions_on_xaxis = [ Pose(Position(-dist_inter_robot * 3, 0), 1.57), Pose(Position(-dist_inter_robot * 2, 0), 1.57), Pose(Position(-dist_inter_robot, 0), 1.57), Pose(Position(dist_inter_robot, 0), 1.57), Pose(Position(2 * dist_inter_robot, 0), 1.57), Pose(Position(3 * dist_inter_robot, 0), 1.57) ] shuffle(positions_on_xaxis) positions_on_yaxis = [ Pose(Position(0, -dist_inter_robot * 3), 0), Pose(Position(0, -dist_inter_robot * 2), 0), Pose(Position(0, -dist_inter_robot), 0), Pose(Position(0, dist_inter_robot), 0), Pose(Position(0, 2 * dist_inter_robot), 0), Pose(Position(0, 3 * dist_inter_robot), 0) ] shuffle(positions_on_yaxis) ''' for i in range(PLAYER_PER_TEAM): self.add_tactic(i, GoToPositionPathfinder(self.game_state, i, positions_on_xaxis[i])) self.add_tactic(i, GoToPositionPathfinder(self.game_state, i, positions_on_yaxis[i])) self.add_condition(i, 0, 1, partial(self.condition, i)) self.add_condition(i, 1, 0, partial(self.condition, i)) ''' self.add_tactic( robot1, GoToPositionPathfinder(self.game_state, self.game_state.get_player_by_role(robot1), positions_on_xaxis[1], cruise_speed=2)) self.add_tactic( robot1, GoToPositionPathfinder(self.game_state, self.game_state.get_player_by_role(robot1), positions_on_yaxis[2], cruise_speed=2)) self.add_condition(robot1, 0, 1, partial(self.condition, robot1)) self.add_condition(robot1, 1, 0, partial(self.condition, robot1)) self.add_tactic( robot2, GoToPositionPathfinder(self.game_state, self.game_state.get_player_by_role(robot2), positions_on_xaxis[3], cruise_speed=2)) self.add_tactic( robot2, GoToPositionPathfinder(self.game_state, self.game_state.get_player_by_role(robot2), positions_on_yaxis[4], cruise_speed=2)) self.add_condition(robot2, 0, 1, partial(self.condition, robot2)) self.add_condition(robot2, 1, 0, partial(self.condition, robot2)) self.add_tactic( robot3, GoToPositionPathfinder(self.game_state, self.game_state.get_player_by_role(robot3), positions_on_xaxis[5], cruise_speed=2)) self.add_tactic( robot3, GoToPositionPathfinder(self.game_state, self.game_state.get_player_by_role(robot3), positions_on_yaxis[0], cruise_speed=2)) self.add_condition(robot3, 0, 1, partial(self.condition, robot3)) self.add_condition(robot3, 1, 0, partial(self.condition, robot3))