Beispiel #1
0
def defender(me,
             my_teammate,
             opponent1,
             opponent2,
             ball,
             strategy,
             one_v_one=False):
    global _offensive, _defensive, _neutral

    if strategy == _offensive:
        dist_to_maintain = 0.85
    elif strategy == _defensive:
        dist_to_maintain = 0.65
    else:
        dist_to_maintain = 0.25

    if strategy == _defensive:
        return Plays.stay_open_for_pass(me, my_teammate, ball)

    if Utilities.am_i_closest_teammate_to_ball(me, my_teammate, ball):
        if Utilities.am_i_closer_to_ball_than_opponents(
                me, opponent1, opponent2, ball):
            if Utilities.is_ball_behind_robot(me, ball):
                return Skills.avoid_own_goal(me, ball)
            else:
                return Skills.clear_ball_from_half(me, ball)
        else:  # I am in charge of stealing the ball
            if Utilities.is_ball_behind_robot(me, ball):
                return Skills.avoid_own_goal(me, ball)
            else:
                closest_opp = Utilities.get_closest_opponent_to_ball(
                    opponent1, opponent2, ball)
                return Plays.steal_ball_from_opponent(me, closest_opp, ball)
    ## My teammate is closer to the ball
    else:
        if Utilities.am_i_too_close_to_teammate(me, my_teammate):
            return Skills.give_my_teammate_some_space(me, my_teammate)
        else:
            if Utilities.is_ball_behind_robot(me, ball):
                return Skills.avoid_own_goal(me, ball)
            elif strategy == _offensive:
                if me.ally1:
                    # call Utilities.are_both_opponents_attacking_goal?
                    return Plays.stay_open_for_pass(me, my_teammate, ball)
                else:  # ally2
                    return Plays.stay_between_points_at_distance(
                        Constants.goal_position_home[0],
                        Constants.goal_position_home[1], ball.xhat, ball.yhat,
                        dist_to_maintain)
            else:  # strategy is defensive
                return Plays.stay_between_points_at_distance(
                    Constants.goal_position_home[0],
                    Constants.goal_position_home[1], ball.xhat, ball.yhat,
                    dist_to_maintain)
Beispiel #2
0
def attacker(me, my_teammate, opponent1, opponent2, ball, strategy, one_v_one=False):
    global _offensive, _defensive, _neutral
    middle_of_goal = 0

    goal_target = 0.6

    if Utilities.am_i_closest_teammate_to_ball(me, my_teammate, ball):
        if Utilities.am_i_closer_to_ball_than_opponents(me, opponent1, opponent2, ball):
            if Utilities.is_ball_behind_robot(me, ball):
                return Skills.avoid_own_goal(me, ball)

            if me.ally1 or one_v_one:
                if ball.yhat > 0: 
                    return Plays.shoot_on_goal(me, ball, goal_target, opponent1, opponent2)
                else: 
                    return Plays.shoot_on_goal(me, ball, -goal_target, opponent1, opponent2)
            else: # I am ally2
                if strategy == _offensive:
                    if (opponent1.xhat < me.xhat and opponent2.xhat < me.xhat):
                        return Plays.shoot_on_goal(me, ball, middle_of_goal, opponent1, opponent2)
                    else:
                        # return Plays.shoot_on_goal(me, ball, middle_of_goal, opponent1, opponent2)
                        return Plays.pass_to_teammate(me, my_teammate, ball) # passes to teammate_future_position
                else: #Defensive
                    if ball.yhat > 0: 
                        return Plays.shoot_on_goal(me, ball, goal_target, opponent1, opponent2)
                    else: 
                        return Plays.shoot_on_goal(me, ball, -goal_target, opponent1, opponent2)

        else: #Basically, we don't have possession and I should be the one to steal the ball
            if Utilities.is_ball_behind_robot(me, ball):
                return Skills.avoid_own_goal(me, ball)
            else:
                closest_opp = Utilities.get_closest_opponent_to_ball(opponent1, opponent2, ball)
                return Plays.steal_ball_from_opponent(me, closest_opp, ball)
    else: #My teammate is closer to the ball than me.
        if Utilities.am_i_too_close_to_teammate(me, my_teammate):
            return Skills.give_my_teammate_some_space(me, my_teammate)
        elif Utilities.is_ball_behind_robot(me, ball):
            return Skills.avoid_own_goal(me, ball)
        else:
            # offensive only if we are behind in points 
            if strategy == _offensive:
                if me.ally1:
                    return Plays.stay_open_for_pass(me, my_teammate, ball)
                else: # I am ally2 
                    return Plays.stay_at_midfield_follow_ball(me, opponent1, opponent2, ball)
            # The secondary robot will always stay at midfield
            else:
                return Plays.stay_at_midfield_follow_ball(me, opponent1, opponent2, ball)
Beispiel #3
0
def defender(me, my_teammate, opponent1, opponent2, ball, strategy, one_v_one=False):
    global _offensive, _defensive, _neutral
    
    if strategy == _offensive:
        dist_to_maintain = 0.85
    elif strategy == _defensive:
        dist_to_maintain = 0.65
    else:
        dist_to_maintain = 0.25

    if strategy == _defensive:
        return Plays.stay_open_for_pass(me, my_teammate, ball) 


    if Utilities.am_i_closest_teammate_to_ball(me, my_teammate, ball):
        if Utilities.am_i_closer_to_ball_than_opponents(me, opponent1, opponent2, ball):
            if Utilities.is_ball_behind_robot(me, ball):
                return Skills.avoid_own_goal(me, ball)
            else:
                return Skills.clear_ball_from_half(me, ball)
        else: # I am in charge of stealing the ball
            if Utilities.is_ball_behind_robot(me, ball):
                return Skills.avoid_own_goal(me, ball)
            else:
                closest_opp = Utilities.get_closest_opponent_to_ball(opponent1, opponent2, ball)
                return Plays.steal_ball_from_opponent(me, closest_opp, ball)
    ## My teammate is closer to the ball
    else: 
        if Utilities.am_i_too_close_to_teammate(me, my_teammate):
            return Skills.give_my_teammate_some_space(me, my_teammate)
        else:
            if Utilities.is_ball_behind_robot(me, ball):
                return Skills.avoid_own_goal(me, ball)
            elif strategy == _offensive:
                if me.ally1:
                    # call Utilities.are_both_opponents_attacking_goal?
                    return Plays.stay_open_for_pass(me, my_teammate, ball)
                else: # ally2
                    return Plays.stay_between_points_at_distance(Constants.goal_position_home[0], Constants.goal_position_home[1], ball.xhat, ball.yhat, dist_to_maintain)
            else: # strategy is defensive
                return Plays.stay_between_points_at_distance(Constants.goal_position_home[0], Constants.goal_position_home[1], ball.xhat, ball.yhat, dist_to_maintain)
Beispiel #4
0
def attacker(me,
             my_teammate,
             opponent1,
             opponent2,
             ball,
             strategy,
             one_v_one=False):
    global _offensive, _defensive, _neutral
    middle_of_goal = 0

    goal_target = 0.6

    if Utilities.am_i_closest_teammate_to_ball(me, my_teammate, ball):
        if Utilities.am_i_closer_to_ball_than_opponents(
                me, opponent1, opponent2, ball):
            if Utilities.is_ball_behind_robot(me, ball):
                return Skills.avoid_own_goal(me, ball)

            if me.ally1 or one_v_one:
                if ball.yhat > 0:
                    return Plays.shoot_on_goal(me, ball, goal_target,
                                               opponent1, opponent2)
                else:
                    return Plays.shoot_on_goal(me, ball, -goal_target,
                                               opponent1, opponent2)
            else:  # I am ally2
                if strategy == _offensive:
                    if (opponent1.xhat < me.xhat and opponent2.xhat < me.xhat):
                        return Plays.shoot_on_goal(me, ball, middle_of_goal,
                                                   opponent1, opponent2)
                    else:
                        # return Plays.shoot_on_goal(me, ball, middle_of_goal, opponent1, opponent2)
                        return Plays.pass_to_teammate(
                            me, my_teammate,
                            ball)  # passes to teammate_future_position
                else:  #Defensive
                    if ball.yhat > 0:
                        return Plays.shoot_on_goal(me, ball, goal_target,
                                                   opponent1, opponent2)
                    else:
                        return Plays.shoot_on_goal(me, ball, -goal_target,
                                                   opponent1, opponent2)

        else:  #Basically, we don't have possession and I should be the one to steal the ball
            if Utilities.is_ball_behind_robot(me, ball):
                return Skills.avoid_own_goal(me, ball)
            else:
                closest_opp = Utilities.get_closest_opponent_to_ball(
                    opponent1, opponent2, ball)
                return Plays.steal_ball_from_opponent(me, closest_opp, ball)
    else:  #My teammate is closer to the ball than me.
        if Utilities.am_i_too_close_to_teammate(me, my_teammate):
            return Skills.give_my_teammate_some_space(me, my_teammate)
        elif Utilities.is_ball_behind_robot(me, ball):
            return Skills.avoid_own_goal(me, ball)
        else:
            # offensive only if we are behind in points
            if strategy == _offensive:
                if me.ally1:
                    return Plays.stay_open_for_pass(me, my_teammate, ball)
                else:  # I am ally2
                    return Plays.stay_at_midfield_follow_ball(
                        me, opponent1, opponent2, ball)
            # The secondary robot will always stay at midfield
            else:
                return Plays.stay_at_midfield_follow_ball(
                    me, opponent1, opponent2, ball)