Exemple #1
0
def rendezvous_prediction(game_info, min_time, persistent):
    '''
    Updates the place and time we will be contacting the ball
    '''

    prediction = game_info.ball_prediction

    for i in range(0, len(prediction.slices), 2):

        aerial = Aerial(game_info.utils_game.my_car)

        #if prediction.slices[i].pos.z > 150:# and prediction.slices[i].time > min_time:
        aerial.target = Vec3_to_vec3(prediction.slices[i].pos,
                                     game_info.team_sign)
        aerial.arrival_time = prediction.slices[i].time
        simulation = aerial.simulate()
        if (vec3_to_Vec3(simulation.location, game_info.team_sign) -
                vec3_to_Vec3(aerial.target,
                             game_info.team_sign)).magnitude() < 30:
            persistent.aerial.target_location = prediction.slices[i].pos
            persistent.aerial.target_time = prediction.slices[i].time
            break

        #else:
        ''' This currently isn't defined, so we're going to skip it for now.
        if prediction.time - game_info.game_time > drive_time(game_info,
        prediction.location,
        game_info.me.boost):
        persistent.hit_ball.action.target = prediction.location
        persistent.hit_ball.action.arrival_time = prediction.time
        break
        '''

    return persistent
    def transition_to_aerial(game_info):
        should_transition = False
        can_hit_aerial = False

        game_info.persistent.aerial.action = RLU_Aerial(
            game_info.utils_game.my_car)

        for ball_slice in game_info.ball_prediction.slices:
            #Skip some slices to save not-so-useful computation
            if ball_slice.pos.z > 300:

                game_info.persistent.aerial.action.target = Vec3_to_vec3(
                    ball_slice.pos, game_info.team_sign)
                game_info.persistent.aerial.action.arrival_time = ball_slice.time

                simulation = game_info.persistent.aerial.action.simulate()

                #Check if we can reach it by an aerial
                if vec3_to_Vec3(
                        simulation.location -
                        game_info.persistent.aerial.action.target,
                        game_info.team_sign).magnitude() < 80:
                    should_transition = True
                    can_hit_aerial = True
                    break

        if not can_hit_aerial:
            game_info.persistent.aerial.action = None

        return should_transition, game_info.persistent
def roll_away_from_target(target, theta, game_info):
    '''
    Returns an orientation mat3 for an air roll shot.  Turns directly away from the dodge direction (target) by angle theta
    Target can either be RLU vec3, or CowBot Vec3.
    '''

    starting_forward = game_info.utils_game.my_car.forward()
    starting_left = game_info.utils_game.my_car.left()
    starting_up = game_info.utils_game.my_car.up()
    starting_orientation = mat3(starting_forward[0], starting_left[0],
                                starting_up[0], starting_forward[1],
                                starting_left[1], starting_up[1],
                                starting_forward[2], starting_left[2],
                                starting_up[2])
    if type(target) == vec3:
        target = vec3_to_Vec3(target, game_info.team_sign)
    car_to_target = Vec3_to_vec3((target - game_info.me.pos).normalize(),
                                 game_info.team_sign)
    axis = theta * cross(car_to_target, starting_up)
    return dot(axis_to_rotation(axis), starting_orientation)
Exemple #4
0
def choose_stationary_takeoff_time(game_info, target_loc, target_time):
    '''
    Decides when to take off for an aerial based on a given target time and place.
    Assumes we're sitting still to start with.
    '''

    aerial = Aerial(game_info.utils_game.my_car)

    aerial.target = Vec3_to_vec3(target_loc, game_info.team_sign)
    current_time = game_info.game_time
    test_interval = [current_time, target_time]
    while abs(test_interval[1] - test_interval[0]) > 1 / 30:
        test_time = (test_interval[0] + test_interval[1]) / 2
        aerial.arrival_time = test_time
        simulation = aerial.simulate()
        if vec3_to_Vec3(simulation.location - aerial.target,
                        game_info.team_sign).magnitude() < 100:
            test_interval = [test_interval[0], test_time]
        else:
            test_interval = [test_time, test_interval[1]]
    return target_time - (test_interval[1] - current_time)
Exemple #5
0
    def to_Curve(self, team_sign):
        '''
        Converts the path to an RLU Curve object that can be followed
        '''

        control_points = []

        #The first arc
        direction1 = self.start - self.center1
        starting_angle = atan2(direction1.y, direction1.x)
        steps = ceil(30 * (self.phi1 / (2 * pi)))
        delta = -self.sgn1 * self.phi1 / steps
        center1 = Vec3_to_vec3(self.center1, team_sign)

        for i in range(1, steps - 2):
            angle = starting_angle + delta * i
            next_point = center1 + abs(self.radius1) * vec3(
                cos(angle), sin(angle), 0)
            normal = normalize(next_point - center1)

            next_control_point = ControlPoint()
            next_control_point.p = next_point
            next_control_point.t = cross(normal)
            next_control_point.n = normal
            control_points.append(next_control_point)

        #The line
        steps = max(10, ceil(self.length_line / 300))
        delta = self.length_line / steps
        tangent = Vec3_to_vec3(
            (self.transition2 - self.transition1).normalize(), team_sign)
        normal = cross(tangent)

        for i in range(0, steps + 1):
            next_point = Vec3_to_vec3(self.transition1,
                                      team_sign) + delta * tangent * i

            next_control_point = ControlPoint()
            next_control_point.p = next_point
            next_control_point.t = tangent
            next_control_point.n = normal
            control_points.append(next_control_point)

        #The second arc
        direction2 = self.transition2 - self.center2
        starting_angle = atan2(direction2.y, direction2.x)
        steps = ceil(30 * (self.phi2 / (2 * pi)))
        delta = -self.sgn2 * self.phi2 / steps
        center2 = Vec3_to_vec3(self.center2, team_sign)

        for i in range(1, steps + 1):
            angle = starting_angle + delta * i
            next_point = center2 + abs(self.radius2) * vec3(
                cos(angle), sin(angle), 0)
            normal = normalize(next_point - center2)

            next_control_point = ControlPoint()
            next_control_point.p = next_point
            next_control_point.t = cross(normal)
            next_control_point.n = normal
            control_points.append(next_control_point)

        curve = Curve(control_points)

        self.RLU_curve = curve
        self.discretized_path = [
            vec3_to_Vec3(point.p, team_sign) for point in control_points
        ]