Exemplo n.º 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)
Exemplo n.º 2
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)