示例#1
0
def _dribble_objective(state: PlayerState):
    side = 1 if state.world_view.side == "l" else -1
    if not state.is_nearest_ball(1):
        state.mode = DEFAULT_MODE
        return determine_objective(state)

    if not state.is_near_ball(KICKABLE_MARGIN):
        return _rush_to_ball_objective(state)

    pos: Coordinate = state.position.get_value()
    if pos.euclidean_distance_from(Coordinate(52.5 * side, 0)) < 24:
        return Objective(
            state,
            lambda: actions.shoot_to(state, Coordinate(55 * side, 0), 100),
            lambda: True, 1)

    should_dribble = state.received_dribble_instruction.get_value() \
                     and state.received_dribble_instruction.last_updated_time >= state.now() - 100

    if not should_dribble:
        target = _choose_pass_target(state)
        if target is not None:
            return Objective(state,
                             lambda: actions.pass_to_player(state, target),
                             lambda: True, 1)
    else:
        state.received_dribble_instruction.set_value(False, state.now())

    if state.is_near_ball(
    ):  # todo temp: and state.action_history.has_looked_for_targets:
        target_coord: Coordinate = Coordinate(52.5 * side, 0)
        opposing_goal_dir = math.degrees(
            calculate_full_origin_angle_radians(target_coord,
                                                state.position.get_value()))
        state.action_history.has_looked_for_targets = False
        return Objective(
            state, lambda: actions.dribble(state, int(opposing_goal_dir)),
            lambda: False, 1)
    return _rush_to_ball_objective(state)
示例#2
0
def determine_objective_goalie_positioning_striker(state: PlayerState):
    # If lost orientation -> blind orient
    if _lost_orientation(state):
        return Objective(state, lambda: actions.blind_orient(state),
                         lambda: True, 1)

    # If ball unknown -> locate ball
    if _ball_unknown(state):
        return Objective(state, lambda: actions.locate_ball(state),
                         lambda: True, 1)

    side = 1 if state.world_view.side == "l" else -1
    if state.world_view.sim_time > 75 and len(state.coach_commands) > 0:
        # First check for dribble, and dribble if needed
        dribble_in_commands: bool = False
        for command in state.coach_commands:
            cmd = command.get_value()
            if "dribble" in cmd and not state.goalie_position_strat_have_dribbled:
                dribble_in_commands = True
                dribble_dir = int(str(cmd).replace("(dribble ", "")[:-1])
                state.goalie_position_strat_have_dribbled = True
                return Objective(
                    state, lambda: actions.dribble(
                        state, int(dribble_dir), dribble_kick_power=20),
                    lambda: True, 1)

        # If already dribble or should not dribble
        if not dribble_in_commands or state.goalie_position_strat_have_dribbled:
            if not state.is_near_ball():
                return _rush_to_ball_objective(state)

            if state.world_view.sim_time > 75:
                for command in state.coach_commands:
                    cmd = command.get_value()
                    if "striker_target_y" in cmd:
                        target_y_value = int(cmd[cmd.index(" ") + 1:-1])

                return Objective(
                    state, lambda: actions.shoot_to(
                        state, Coordinate(55 * side, target_y_value), 75),
                    lambda: True, 1)

    return Objective(state, lambda: [], lambda: True, 1)
示例#3
0
def determine_objective_field_default(state: PlayerState):
    state.intercepting = False
    # If lost orientation -> blind orient
    if _lost_orientation(state):
        return Objective(state, lambda: actions.blind_orient(state),
                         lambda: True, 1)

    opponent_side = "r" if state.world_view.side == "l" else "l"
    # If game not started or other team starting -> Idle orientation
    if state.world_view.game_state == 'before_kick_off' or state.world_view.game_state == "kick_off_{0}".format(
            opponent_side) or "goal" in state.world_view.game_state:
        return Objective(state, lambda: actions.idle_orientation(state),
                         lambda: True, 1)

    # If some fault has been made by our team -> position optimally
    if "fault_{0}".format(
            state.world_view.side) in state.world_view.game_state:
        return _position_optimally_objective(state)

    # If we have a free kick, corner_kick, kick_in or kick_off
    #   If closest -> Go to ball and pass, else position optimally
    if state.world_view.game_state == "free_kick_{0}".format(state.world_view.side) \
            or state.world_view.game_state == "corner_kick_{0}".format(state.world_view.side) \
            or state.world_view.game_state == "kick_in_{0}".format(state.world_view.side) \
            or state.world_view.game_state == "kick_off_{0}".format(state.world_view.side) \
            or state.world_view.game_state == "offside_{0}".format(opponent_side):
        if _ball_unknown(state):
            return _locate_ball_objective(state)
        if state.is_near_ball(KICKABLE_MARGIN):
            if state.world_view.sim_time - state.action_history.last_look_for_pass_targets > 2:
                return Objective(state,
                                 lambda: actions.look_for_pass_target(state),
                                 lambda: True, 2)
            if _choose_pass_target(state, must_pass=True) is not None:
                return Objective(
                    state, lambda: actions.pass_to_player(
                        state, _choose_pass_target(state, must_pass=True)),
                    lambda: True, 1)
            else:
                return Objective(state,
                                 lambda: actions.look_for_pass_target(state),
                                 lambda: True, 2)
        elif state.is_nearest_ball(1):
            return _jog_to_ball_objective(state)
        else:
            return _position_optimally_objective(state)

    # If in dribbling mode -> Dribble
    if state.mode is DRIBBLING_MODE:
        return _dribble_objective(state)

    # If in possession mode -> Pass
    if state.mode is POSSESSION_MODE:
        return _pass_objective(state)

    # If position known, but ball not -> Locate ball
    if _ball_unknown(state):
        return _locate_ball_objective(state)

    # If in possession of ball -> dribble!
    if state.is_near_ball() and state.is_nearest_ball(1):
        state.mode = DRIBBLING_MODE
        return _dribble_objective(state)

    required_degree = calculate_required_degree(state)
    if state.is_nearest_ball(required_degree):
        intercept_actions = actions.intercept_2(state)
        state.intercepting = True
        if intercept_actions is not None:
            return Objective(state, lambda: intercept_actions)
        else:
            return _rush_to_ball_objective(state)

    # If ball not incoming -> Position optimally while looking at ball
    if not state.ball_incoming() and not configurations.USING_PASS_CHAIN_STRAT:
        if state.is_test_player():
            debug_msg(str(state.now()) + " Position optimally!", "ACTIONS")
        return _position_optimally_objective(state)

    if state.is_test_player():
        debug_msg(str(state.now()) + " Idle orientation!", "ACTIONS")

    return Objective(state, lambda: actions.idle_orientation(state),
                     lambda: True, 1)
示例#4
0
def determine_objective_goalie_default(state: PlayerState):
    opponent_side = "r" if state.world_view.side == "l" else "l"
    # If goalie and goal_kick -> Go to ball and pass
    if state.world_view.game_state == "goal_kick_{0}".format(
            state.world_view.side) and state.num == 1:
        debug_msg(
            str(state.now()) + " | goal kick -> got to ball and pass",
            "GOALIE")
        if state.is_near_ball(KICKABLE_MARGIN):
            return _pass_objective(state, must_pass=True)
        else:
            return _jog_to_ball_objective(state)

    # If game not started or other team starting -> Idle orientation
    if state.world_view.game_state == 'before_kick_off' or state.world_view.game_state == "kick_off_{0}".format(
            opponent_side) or ("goal_r" == state.world_view.game_state
                               or "goal_l" == state.world_view.game_state):
        debug_msg(
            str(state.now()) +
            " | If game not started or other team starting -> Idle orientation",
            "GOALIE")
        return Objective(state, lambda: actions.idle_orientation(state),
                         lambda: True, 1)

    # If lost_orientation -> blind orient
    if _lost_orientation(state):
        debug_msg(
            str(state.now()) + " | lost orientation -> blind orient", "GOALIE")
        return Objective(state, lambda: actions.blind_orient(state),
                         lambda: True, 1)

    # If ball unknown -> locate ball
    if _ball_unknown(state):
        debug_msg(
            str(state.now()) + " | ball unknown -> locate ball", "GOALIE")
        return Objective(state, lambda: actions.locate_ball(state),
                         lambda: True, 1)

    # If some fault has been made by our team -> Position optimally
    if "fault_{0}".format(
            state.world_view.side) in state.world_view.game_state:
        debug_msg(
            str(state.now()) + " | Team made fault -> position optimally",
            "GOALIE")
        return _position_optimally_objective_goalie(state)

    # If we have a free kick, corner_kick, kick_in, kick_off or goal_kick
    # If closest -> Go to ball and pass, else position optimally
    if state.world_view.game_state == "free_kick_{0}".format(state.world_view.side) \
            or state.world_view.game_state == "corner_kick_{0}".format(state.world_view.side) \
            or state.world_view.game_state == "kick_in_{0}".format(state.world_view.side) \
            or state.world_view.game_state == "goal_kick_{0}".format(state.world_view.side) \
            or state.world_view.game_state == "offside_{0}".format(opponent_side):
        debug_msg(
            str(state.now()) +
            " | free_kick, corner_kick, kick_in, kick_off, goal_kick, offside -> go to ball or position optimally",
            "GOALIE")
        if _ball_unknown(state):
            return _locate_ball_objective(state)
        if state.is_near_ball(KICKABLE_MARGIN):
            if state.world_view.sim_time - state.action_history.last_look_for_pass_targets > 2:
                return Objective(state,
                                 lambda: actions.look_for_pass_target(state),
                                 lambda: True, 2)
            if _choose_pass_target(state, must_pass=True) is not None:
                return Objective(
                    state, lambda: actions.pass_to_player(
                        state, _choose_pass_target(state, must_pass=True)),
                    lambda: True, 1)
            else:
                return Objective(state,
                                 lambda: actions.look_for_pass_target(state),
                                 lambda: True, 2)
        elif state.is_nearest_ball(1):
            return _jog_to_ball_objective(state)
        else:
            return _position_optimally_objective_goalie(state)

    ball: Ball = state.world_view.ball.get_value()

    # If in possession of the ball -> Pass to team mate
    if state.is_near_ball(KICKABLE_MARGIN):
        pass_target = _choose_pass_target(state)
        if pass_target is not None:
            debug_msg(
                str(state.now()) +
                " | in possession, pass target found -> pass to teammate",
                "GOALIE")
            return Objective(
                state, lambda: actions.pass_to_player(
                    state, _choose_pass_target(state)), lambda: True, 1)
        # No suitable pass target
        debug_msg(
            str(state.now()) +
            " | in possession, pass target not found -> look for pass target",
            "GOALIE")
        return Objective(state, lambda: actions.look_for_pass_target(state),
                         lambda: True, 1)

    # If ball coming to goalie inside box -> Catch ball
    positions = ball.project_ball_position(2, 0)
    if positions is not None and state.is_inside_own_box():
        debug_msg(
            str(state.now()) + " | Ball incoming inside box -> Catch ball",
            "GOALIE")
        ball_pos_1_tick: Coordinate = positions[0]
        if ball_pos_1_tick.euclidean_distance_from(
                state.position.get_value()) < CATCHABLE_MARGIN:
            return Objective(
                state, lambda: actions.catch_ball(state, ball_pos_1_tick),
                lambda: True, 1)

    # If ball coming towards us or ball will hit goal soon -> Intercept
    if (ball.will_hit_goal_within(ticks=5)
            or (state.is_nearest_ball(1) and state.is_ball_inside_own_box())):
        debug_msg(
            str(state.now()) +
            " | ball coming towards us or ball will hit goal soon -> run to ball and catch!",
            "GOALIE")
        intercept_actions = actions.intercept_2(state, "catch")
        if intercept_actions is not None:
            return Objective(state, lambda: intercept_actions)
        else:
            return _rush_to_ball_objective(state)

    # If position not alligned with ball y-position -> Adjust y-position
    if state.position.is_value_known(
    ) and state.world_view.ball.is_value_known(
    ) and not configurations.USING_PASS_CHAIN_STRAT:
        debug_msg(
            str(state.now()) + " | Position not optimal -> adjust position",
            "GOALIE")
        return _position_optimally_objective_goalie(state)

    # If nothing to do -> Face ball
    debug_msg(str(state.now()) + " | Nothing to do -> Face ball", "GOALIE")
    return Objective(state, lambda: actions.face_ball(state), lambda: True, 1)