def __init__(self, p_game_state):
        super().__init__(p_game_state)
        our_goal = self.game_state.field.our_goal_pose

        role_to_positions = {
            Role.FIRST_ATTACK:
            Pose.from_values(our_goal.position.x / 8,
                             GameState().field.top * 2 / 3),
            Role.SECOND_ATTACK:
            Pose.from_values(our_goal.position.x / 8,
                             GameState().field.top / 3),
            Role.MIDDLE:
            Pose.from_values(our_goal.position.x / 8, 0),
            Role.FIRST_DEFENCE:
            Pose.from_values(our_goal.position.x / 8,
                             GameState().field.bottom / 3),
            Role.SECOND_DEFENCE:
            Pose.from_values(our_goal.position.x / 8,
                             GameState().field.bottom * 2 / 3)
        }

        goalkeeper = self.game_state.get_player_by_role(Role.GOALKEEPER)
        self.create_node(
            Role.GOALKEEPER,
            GoalKeeper(self.game_state, goalkeeper, penalty_kick=True))

        self.assign_tactics(role_to_positions)
    def __init__(self, game_state):
        super().__init__(game_state)

        # Attribution des joueurs

        center_offset = game_state.field.center_circle_radius

        # Positions objectifs des joueurs
        # FIXME: This is bad, the orientation of the player will always be the same,
        # independently of if we are in a positive or negative x
        attack_top_position = Pose.from_values(GameState().field.our_goal_x / 10,
                                               GameState().field.bottom * 3 / 5, 0)
        attack_bottom_position = Pose.from_values(GameState().field.our_goal_x / 10,
                                                  GameState().field.top * 3 / 5, 0)
        middle_position = Pose.from_values(center_offset + GameState().field.our_goal_x / 10, 0, 0)

        defense_top_position = Pose.from_values(GameState().field.our_goal_x / 2,
                                                GameState().field.top / 10, 0)
        defense_bottom_position = Pose.from_values(GameState().field.our_goal_x / 2,
                                                   GameState().field.bottom / 10, 0)

        goalkeeper = self.assigned_roles[Role.GOALKEEPER]
        self.create_node(Role.GOALKEEPER, GoalKeeper(game_state, goalkeeper))

        role_to_positions = {Role.FIRST_ATTACK: attack_top_position,
                             Role.SECOND_ATTACK: attack_bottom_position,
                             Role.MIDDLE: middle_position,
                             Role.FIRST_DEFENCE: defense_top_position,
                             Role.SECOND_DEFENCE: defense_bottom_position}

        self.assign_tactics(role_to_positions)
Пример #3
0
    def __init__(self, p_game_state):
        super().__init__(p_game_state)

        formation_defender = [
            p for r, p in self.assigned_roles.items() if r in self.DEFENDERS
        ]
        formation_around_ball = [
            p for r, p in self.assigned_roles.items()
            if r not in self.DEFENDERS and r != Role.GOALKEEPER
        ]
        for role, player in self.assigned_roles.items():
            if role == Role.GOALKEEPER:
                self.create_node(Role.GOALKEEPER,
                                 GoalKeeper(self.game_state, player))
            elif role in self.DEFENDERS:
                self.create_node(
                    role,
                    AlignToDefenseWall(self.game_state,
                                       player,
                                       robots_in_formation=formation_defender,
                                       object_to_block=self.game_state.ball,
                                       stay_away_from_ball=True,
                                       cruise_speed=1))
            else:
                self.create_node(
                    role,
                    AlignAroundTheBall(
                        self.game_state,
                        player,
                        robots_in_formation=formation_around_ball))
    def __init__(self, game_state: GameState, number_of_players: int = 4):
        super().__init__(game_state)
        self.number_of_players = number_of_players
        self.robots = []
        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_to_consider = [
            Role.FIRST_ATTACK, Role.SECOND_ATTACK, Role.MIDDLE,
            Role.FIRST_DEFENCE, Role.SECOND_DEFENCE
        ]

        goalkeeper = self.game_state.get_player_by_role(Role.GOALKEEPER)

        self.add_tactic(Role.GOALKEEPER,
                        GoalKeeper(self.game_state, goalkeeper, ourgoal))

        role_by_robots = [(i, self.game_state.get_player_by_role(i))
                          for i in roles_to_consider]
        self.robots = [
            player for _, player in role_by_robots if player is not None
        ]
        for role, player in role_by_robots:
            if player:
                self.add_tactic(
                    role,
                    AlignToDefenseWall(self.game_state, player, self.robots))
Пример #5
0
    def __init__(self, game_state):
        super().__init__(game_state)

        their_goal = game_state.field.their_goal
        role_to_positions = {
            Role.FIRST_ATTACK:
            Pose.from_values(their_goal.x / 8,
                             self.game_state.field.top * 2 / 3),
            Role.SECOND_ATTACK:
            Pose.from_values(their_goal.x / 8, self.game_state.field.top / 3),
            Role.MIDDLE:
            Pose.from_values(their_goal.x / 8, 0),
            Role.FIRST_DEFENCE:
            Pose.from_values(their_goal.x / 8,
                             self.game_state.field.bottom / 3),
            Role.SECOND_DEFENCE:
            Pose.from_values(their_goal.x / 8,
                             self.game_state.field.bottom * 2 / 3)
        }

        goalkeeper = self.assigned_roles[Role.GOALKEEPER]
        self.create_node(Role.GOALKEEPER,
                         GoalKeeper(game_state, goalkeeper, penalty_kick=True))

        self.assign_tactics(role_to_positions)
    def __init__(self, p_game_state):
        super().__init__(p_game_state)

        # Positions objectifs des joueurs
        attack_top_position = Pose.from_values(
            self.game_state.field.our_goal_x / 15,
            self.game_state.field.bottom * 3 / 5, 0)
        attack_bottom_position = Pose.from_values(
            self.game_state.field.our_goal_x / 15,
            self.game_state.field.top * 3 / 5, 0)
        middle_position = Pose.from_values(
            self.game_state.field.our_goal_x / 15, 0, 0)
        defense_top_position = Pose.from_values(
            self.game_state.field.our_goal_x / 2,
            self.game_state.field.top / 3, 0)
        defense_bottom_position = Pose.from_values(
            self.game_state.field.our_goal_x / 2,
            self.game_state.field.bottom / 3, 0)

        goalkeeper = self.assigned_roles[Role.GOALKEEPER]
        self.create_node(Role.GOALKEEPER,
                         GoalKeeper(self.game_state, goalkeeper))

        role_to_positions = {
            Role.FIRST_ATTACK: attack_top_position,
            Role.SECOND_ATTACK: attack_bottom_position,
            Role.MIDDLE: middle_position,
            Role.FIRST_DEFENCE: defense_top_position,
            Role.SECOND_DEFENCE: defense_bottom_position
        }

        self.assign_tactics(role_to_positions)
Пример #7
0
    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))
Пример #8
0
    def __init__(self, p_game_state):
        super().__init__(p_game_state, keep_roles=False)

        # TODO: HARDCODED ID FOR QUALIFICATION, REMOVE LATER
        self.roles_graph = {r: Graph() for r in Role}
        role_mapping = {
            Role.GOALKEEPER: 2,
            Role.MIDDLE: 4,
            Role.FIRST_ATTACK: 6
        }
        self.game_state.map_players_to_roles_by_player_id(role_mapping)

        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_to_consider = [Role.MIDDLE, Role.FIRST_ATTACK, Role.GOALKEEPER]
        role_by_robots = [(i, self.game_state.get_player_by_role(i))
                          for i in roles_to_consider]
        self.robots = [
            player for _, player in role_by_robots if player is not None
        ]

        goalkeeper = self.game_state.get_player_by_role(Role.GOALKEEPER)

        self.add_tactic(
            Role.GOALKEEPER,
            GoalKeeper(self.game_state, goalkeeper, ourgoal,
                       penalty_kick=True))

        for index, player in role_by_robots:
            if player:
                self.add_tactic(
                    index,
                    PositionForPass(self.game_state,
                                    player,
                                    auto_position=True,
                                    robots_in_formation=self.robots))
                self.add_tactic(
                    index,
                    GoKick(self.game_state, player, target=self.theirgoal))

                self.add_condition(index, 0, 1,
                                   partial(self.is_closest, player))
                self.add_condition(index, 1, 0,
                                   partial(self.is_not_closest, player))
                self.add_condition(index, 1, 1,
                                   partial(self.has_kicked, player))
    def __init__(self, game_state: GameState, number_of_players: int = 3):
        super().__init__(game_state)

        role_mapping = {
            Role.GOALKEEPER: 4,
            Role.FIRST_ATTACK: 3,
            Role.SECOND_ATTACK: 2
        }
        self.game_state.map_players_to_roles_by_player_id(role_mapping)

        self.number_of_players = number_of_players
        self.robots = []
        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_to_consider = [Role.FIRST_ATTACK, Role.SECOND_ATTACK]

        goalkeeper = self.game_state.get_player_by_role(Role.GOALKEEPER)
        self.add_tactic(
            Role.GOALKEEPER,
            GoalKeeper(self.game_state, goalkeeper, target=ourgoal))

        role_by_robots = [(i, self.game_state.get_player_by_role(i))
                          for i in roles_to_consider]
        self.robots = [
            player for _, player in role_by_robots if player is not None
        ]
        for role, player in role_by_robots:
            if player:
                self.add_tactic(
                    role,
                    AlignToDefenseWall(self.game_state, player, self.robots))
                self.add_tactic(
                    role, GoKick(self.game_state,
                                 player,
                                 target=self.theirgoal))

                self.add_condition(role, 0, 1, partial(self.is_closest,
                                                       player))
                self.add_condition(role, 1, 1, partial(self.is_closest,
                                                       player))
                self.add_condition(role, 1, 0,
                                   partial(self.is_not_closest, player))
Пример #10
0
    def __init__(self, game_state):
        super().__init__(game_state)

        our_goal = game_state.field.our_goal_pose
        their_goal = game_state.field.their_goal_pose

        role_to_positions = {Role.SECOND_ATTACK:  Pose.from_values(our_goal.position.x / 8, GameState().field.top * 2 / 3),
                             Role.MIDDLE:         Pose.from_values(our_goal.position.x / 8, GameState().field.top / 3),
                             Role.FIRST_DEFENCE:  Pose.from_values(our_goal.position.x / 8, GameState().field.bottom / 3),
                             Role.SECOND_DEFENCE: Pose.from_values(our_goal.position.x / 8, GameState().field.bottom * 2 / 3)}

        kicker = self.assigned_roles[Role.FIRST_ATTACK]
        self.create_node(Role.FIRST_ATTACK, GoKick(game_state, kicker, their_goal, kick_force=KickForce.HIGH))

        goalkeeper = self.assigned_roles[Role.GOALKEEPER]
        self.create_node(Role.GOALKEEPER, GoalKeeper(game_state, goalkeeper, penalty_kick=True))

        self.assign_tactics(role_to_positions)
Пример #11
0
    def __init__(self, p_game_state):
        super().__init__(p_game_state)
        our_goal = self.game_state.field.our_goal_pose

        self.create_node(Role.GOALKEEPER,
                         GoalKeeper(self.game_state, self.assigned_roles[Role.GOALKEEPER]))

        attacker = self.assigned_roles[Role.FIRST_ATTACK]
        node_idle = self.create_node(Role.FIRST_ATTACK, Stop(self.game_state, attacker))
        node_go_kick = self.create_node(Role.FIRST_ATTACK, GoKick(self.game_state,
                                                                  attacker,
                                                                  target=our_goal,
                                                                  kick_force=KickForce.HIGH))

        player_has_kicked = partial(self.has_kicked, Role.FIRST_ATTACK)

        node_idle.connect_to(node_go_kick, when=self.ball_is_outside_goal)
        node_go_kick.connect_to(node_idle, when=self.ball_is_inside_goal)
        node_go_kick.connect_to(node_go_kick, when=player_has_kicked)
Пример #12
0
    def __init__(self, p_game_state):
        super().__init__(p_game_state)

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

        for role, player in self.assigned_roles.items():
            if role is Role.GOALKEEPER:
                self.create_node(role, GoalKeeper(self.game_state, player))
            else:
                node_pass = self.create_node(
                    role,
                    PositionForPass(self.game_state,
                                    player,
                                    auto_position=True,
                                    robots_in_formation=robots_in_formation))
                node_go_kick = self.create_node(
                    role,
                    GoKick(self.game_state, player, auto_update_target=True))
                node_wait_for_pass = self.create_node(
                    role, ReceivePass(self.game_state, player))

                player_is_closest = partial(self.is_closest_not_goalkeeper,
                                            player)
                player_is_not_closest = partial(self.is_not_closest, player)
                player_has_kicked = partial(self.has_kicked, player)
                player_is_receiving_pass = partial(
                    self.ball_going_toward_player, player)
                player_is_not_receiving_pass = partial(
                    self.ball_not_going_toward_player, player)
                player_has_received_ball = partial(self.has_received, player)

                node_pass.connect_to(node_go_kick, when=player_is_closest)
                node_pass.connect_to(node_wait_for_pass,
                                     when=player_is_receiving_pass)
                node_wait_for_pass.connect_to(node_go_kick,
                                              when=player_has_received_ball)
                node_wait_for_pass.connect_to(
                    node_pass, when=player_is_not_receiving_pass)
                node_go_kick.connect_to(node_pass, when=player_is_not_closest)
                node_go_kick.connect_to(node_go_kick, when=player_has_kicked)
Пример #13
0
    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_to_consider = [
            Role.FIRST_ATTACK, Role.SECOND_ATTACK, Role.MIDDLE,
            Role.FIRST_DEFENCE, Role.SECOND_DEFENCE
        ]
        position_list = [
            Pose(
                Position(self.theirgoal.position.x / 8,
                         GameState().const["FIELD_Y_TOP"] * 2 / 3)),
            Pose(
                Position(self.theirgoal.position.x / 8,
                         GameState().const["FIELD_Y_TOP"] / 3)),
            Pose(Position(self.theirgoal.position.x / 8, 0)),
            Pose(
                Position(self.theirgoal.position.x / 8,
                         GameState().const["FIELD_Y_BOTTOM"] / 3)),
            Pose(
                Position(self.theirgoal.position.x / 8,
                         GameState().const["FIELD_Y_BOTTOM"] * 2 / 3))
        ]
        postions_for_roles = dict(zip(roles_to_consider, position_list))

        goalkeeper = self.game_state.get_player_by_role(Role.GOALKEEPER)

        self.add_tactic(
            Role.GOALKEEPER,
            GoalKeeper(self.game_state, goalkeeper, ourgoal,
                       penalty_kick=True))

        for role in roles_to_consider:
            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))
Пример #14
0
    def __init__(self, p_game_state):
        super().__init__(p_game_state)

        their_goal = self.game_state.field.their_goal_pose

        node_pass_to_second_attack = self.create_node(
            Role.FIRST_ATTACK,
            PassToPlayer(self.game_state,
                         self.assigned_roles[Role.FIRST_ATTACK],
                         args=[self.assigned_roles[Role.SECOND_ATTACK].id]))

        node_pass_to_middle = self.create_node(
            Role.FIRST_ATTACK,
            PassToPlayer(self.game_state,
                         self.assigned_roles[Role.FIRST_ATTACK],
                         args=[self.assigned_roles[Role.MIDDLE].id]))

        node_go_kick = self.create_node(
            Role.FIRST_ATTACK,
            GoKick(self.game_state, self.assigned_roles[Role.FIRST_ATTACK],
                   their_goal))

        second_attack_is_best_receiver = partial(self.is_best_receiver,
                                                 Role.SECOND_ATTACK)
        middle_is_best_receiver = partial(self.is_best_receiver, Role.MIDDLE)
        current_tactic_succeeded = partial(self.current_tactic_succeed,
                                           Role.FIRST_ATTACK)

        node_pass_to_second_attack.connect_to(
            node_pass_to_middle, when=second_attack_is_best_receiver)
        node_pass_to_second_attack.connect_to(node_go_kick,
                                              when=middle_is_best_receiver)
        node_pass_to_second_attack.connect_to(node_pass_to_second_attack,
                                              when=current_tactic_succeeded)
        node_pass_to_middle.connect_to(node_pass_to_second_attack,
                                       when=current_tactic_succeeded)
        node_go_kick.connect_to(node_pass_to_second_attack,
                                when=current_tactic_succeeded)

        self.create_node(
            Role.GOALKEEPER,
            GoalKeeper(self.game_state, self.assigned_roles[Role.GOALKEEPER]))
Пример #15
0
 def setUp(self):
     self.game_state = GameState()
     self.game = Game()
     self.game.set_referee(Referee())
     self.game.ball = Ball()
     game_world = ReferenceTransferObject(self.game)
     game_world.set_team_color_svc(TeamColorService(TeamColor.YELLOW))
     self.game_state.set_reference(game_world)
     self.game_state.game.friends.players[0].pose = Pose(
         Position(-4450, 0), 0)
     self.tactic1 = GoalKeeper(
         self.game_state,
         self.game_state.game.friends.players[A_GOAL_PLAYER_ID])
     self.tactic2 = Stop(self.game_state,
                         self.game_state.game.friends.players[A_PLAYER_ID])
     self.node1 = Node(self.tactic1)
     self.node2 = Node(self.tactic2)
     self.vertex1 = Vertex(0, foo)
     self.vertex2 = Vertex(1, foo2)
     self.a_player = OurPlayer(TeamColor.BLUE, 0)
Пример #16
0
    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_to_consider = [Role.FIRST_ATTACK, Role.SECOND_ATTACK, Role.MIDDLE,
                             Role.FIRST_DEFENCE, Role.SECOND_DEFENCE]
        role_by_robots = [(i, self.game_state.get_player_by_role(i)) for i in roles_to_consider]

        goalkeeper = self.game_state.get_player_by_role(Role.GOALKEEPER)

        self.add_tactic(Role.GOALKEEPER, GoalKeeper(self.game_state, goalkeeper, ourgoal))

        for index, player in role_by_robots:
            if player:
                self.add_tactic(index, PositionForPass(self.game_state, player, auto_position=True))
                self.add_tactic(index, GoKick(self.game_state, player, auto_update_target=True))

                self.add_condition(index, 0, 1, partial(self.is_closest, player))
                self.add_condition(index, 1, 0, partial(self.is_not_closest, player))
                self.add_condition(index, 1, 1, partial(self.has_kicked, player))
Пример #17
0
    def __init__(self,
                 game_state: GameState,
                 can_kick=True,
                 multiple_cover=True,
                 stay_away_from_ball=False):
        super().__init__(game_state)

        their_goal = self.game_state.field.their_goal_pose

        # If we can not kick, the attackers are part of the defense wall
        # TODO find a more useful thing to do for the attackers when we are in a no kick state
        self.can_kick = can_kick
        self.multiple_cover = multiple_cover
        self.defensive_role = DEFENSIVE_ROLE.copy()
        self.cover_role = COVER_ROLE.copy()

        self.robots_in_wall_formation = []
        self.robots_in_cover_formation = []
        self.attackers = []
        self.cover_to_coveree = {}
        self.cover_to_formation = {}

        self._dispatch_player()

        for role, player in self.assigned_roles.items():
            if role == Role.GOALKEEPER:
                self.create_node(Role.GOALKEEPER,
                                 GoalKeeper(self.game_state, player))
            elif player in self.attackers:
                node_position_pass = self.create_node(
                    role,
                    PositionForPass(self.game_state,
                                    player,
                                    robots_in_formation=self.attackers,
                                    auto_position=True))
                node_go_kick = self.create_node(
                    role, GoKick(self.game_state, player, target=their_goal))
                node_wait_for_pass = self.create_node(
                    role, ReceivePass(self.game_state, player))

                attacker_should_go_kick = partial(self.should_go_kick, player)
                attacker_should_not_go_kick = partial(self.should_not_go_kick,
                                                      player)
                attacker_has_kicked = partial(self.has_kicked, role)
                player_is_receiving_pass = partial(
                    self.ball_going_toward_player, player)
                player_is_not_receiving_pass = partial(
                    self.ball_not_going_toward_player, player)
                player_has_received_ball = partial(self.has_received, player)

                node_position_pass.connect_to(node_go_kick,
                                              when=attacker_should_go_kick)
                node_position_pass.connect_to(node_wait_for_pass,
                                              when=player_is_receiving_pass)
                node_wait_for_pass.connect_to(node_go_kick,
                                              when=player_has_received_ball)
                node_wait_for_pass.connect_to(
                    node_position_pass, when=player_is_not_receiving_pass)
                node_go_kick.connect_to(node_position_pass,
                                        when=attacker_should_not_go_kick)
                node_go_kick.connect_to(node_go_kick, when=attacker_has_kicked)
            elif role in self.cover_role:
                enemy_to_block = self.cover_to_coveree[player]
                formation = self.cover_to_formation[player]
                node_align_to_covered_object = self.create_node(
                    role,
                    AlignToDefenseWall(
                        self.game_state,
                        player,
                        robots_in_formation=formation,
                        object_to_block=enemy_to_block,
                        stay_away_from_ball=stay_away_from_ball))
                node_position_pass = self.create_node(
                    role,
                    PositionForPass(
                        self.game_state,
                        player,
                        robots_in_formation=self.robots_in_cover_formation,
                        auto_position=True))

                node_go_kick = self.create_node(
                    role, GoKick(self.game_state, player, target=their_goal))
                node_wait_for_pass = self.create_node(
                    role, ReceivePass(self.game_state, player))

                player_is_receiving_pass = partial(
                    self.ball_going_toward_player, player)
                player_is_not_receiving_pass = partial(
                    self.ball_not_going_toward_player, player)
                player_has_received_ball = partial(self.has_received, player)
                player_has_kicked = partial(self.has_kicked, role)

                node_align_to_covered_object.connect_to(
                    node_position_pass,
                    when=self.game_state.field.is_ball_in_our_goal_area)
                node_position_pass.connect_to(
                    node_align_to_covered_object,
                    when=self.game_state.field.is_ball_outside_our_goal_area)
                node_wait_for_pass.connect_to(node_go_kick,
                                              when=player_has_received_ball)
                node_wait_for_pass.connect_to(
                    node_align_to_covered_object,
                    when=player_is_not_receiving_pass)
                node_position_pass.connect_to(node_wait_for_pass,
                                              when=player_is_receiving_pass)
                node_go_kick.connect_to(node_align_to_covered_object,
                                        when=player_has_kicked)
            else:
                node_align_to_defense_wall = \
                    self.create_node(role, AlignToDefenseWall(self.game_state,
                                                              player,
                                                              robots_in_formation=self.robots_in_wall_formation,
                                                              object_to_block=GameState().ball,
                                                              stay_away_from_ball=stay_away_from_ball))
                node_position_pass = self.create_node(
                    role,
                    PositionForPass(
                        self.game_state,
                        player,
                        robots_in_formation=self.robots_in_wall_formation,
                        auto_position=True))

                node_go_kick = self.create_node(
                    role, GoKick(self.game_state, player, target=their_goal))
                node_wait_for_pass = self.create_node(
                    role, ReceivePass(self.game_state, player))

                player_is_receiving_pass = partial(
                    self.ball_going_toward_player, player)
                player_is_not_receiving_pass = partial(
                    self.ball_not_going_toward_player, player)
                player_has_received_ball = partial(self.has_received, player)
                player_has_kicked = partial(self.has_kicked, role)

                node_align_to_defense_wall.connect_to(
                    node_position_pass,
                    when=self.game_state.field.is_ball_in_our_goal_area)
                node_position_pass.connect_to(
                    node_align_to_defense_wall,
                    when=self.game_state.field.is_ball_outside_our_goal_area)

                node_wait_for_pass.connect_to(node_go_kick,
                                              when=player_has_received_ball)
                node_go_kick.connect_to(node_align_to_defense_wall,
                                        when=player_has_kicked)
                node_position_pass.connect_to(node_wait_for_pass,
                                              when=player_is_receiving_pass)
                node_position_pass.connect_to(
                    node_align_to_defense_wall,
                    when=player_is_not_receiving_pass)
Пример #18
0
    def __init__(self, p_game_state, can_kick_in_goal):
        super().__init__(p_game_state)

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

        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.create_node(Role.GOALKEEPER,
                                 GoalKeeper(self.game_state, player))
            else:
                node_pass = self.create_node(
                    role,
                    PositionForPass(
                        self.game_state,
                        player,
                        robots_in_formation=formation,
                        auto_position=True,
                        forbidden_areas=self.game_state.field.border_limits +
                        forbidden_areas))
                node_wait_for_pass = self.create_node(
                    role, ReceivePass(self.game_state, player))
                initial_position_for_pass_center[
                    role] = node_pass.tactic.area.center  # Hack
                node_go_kick = self.create_node(
                    role,
                    GoKick(
                        self.game_state,
                        player,
                        auto_update_target=True,
                        can_kick_in_goal=can_kick_in_goal,
                        forbidden_areas=self.game_state.field.border_limits +
                        forbidden_areas))

                player_is_not_closest = partial(self.is_not_closest, player)
                player_has_kicked = partial(self.has_kicked, player)
                player_is_receiving_pass = partial(
                    self.ball_going_toward_player, player)
                player_is_not_receiving_pass = partial(
                    self.ball_not_going_toward_player, player)
                player_has_received_ball = partial(self.has_received, player)
                player_is_closest = partial(self.is_closest_not_goalkeeper,
                                            player)

                node_pass.connect_to(node_wait_for_pass,
                                     when=player_is_receiving_pass)
                node_pass.connect_to(node_go_kick, when=player_is_closest)
                node_wait_for_pass.connect_to(node_go_kick,
                                              when=player_has_received_ball)
                node_wait_for_pass.connect_to(
                    node_pass, when=player_is_not_receiving_pass)
                node_go_kick.connect_to(node_pass, when=player_is_not_closest)
                node_go_kick.connect_to(node_go_kick, when=player_has_kicked)

        # 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.has_ball_move = False