Пример #1
0
    def execute(self, data):
        ball_land_eta = max(predict.time_of_arrival_at_height(data.ball, datalibs.BALL_RADIUS + 1).time, 0)
        ball_land_loc = predict.move_ball(data.ball.copy(), ball_land_eta).location

        bias = (ball_land_loc - datalibs.get_goal_location(data.enemy.team)).rescale(20)
        dest = ball_land_loc + bias
        data.renderer.draw_line_3d(data.car.location.tuple(), dest.tuple(), data.renderer.create_color(255, 255, 0, 255))
        data.renderer.draw_line_3d(data.ball.location.tuple(), dest.tuple(), data.renderer.create_color(255, 255, 0, 255))
        return moves.go_towards_point_with_timing(data, dest, ball_land_eta, True)
Пример #2
0
 def execute(self, data):
     own_goal = datalibs.get_goal_location(data.car.team)
     dist = own_goal.dist(data.car.location)
     if dist > 240:
         data.renderer.draw_line_3d(data.car.location.tuple(), own_goal.tuple(), self.color(data.renderer))
         if moves.consider_dodge(data, own_goal, min_dist=1500):
             return data.agent.dodge_control.continue_dodge(data)
         return moves.go_to_and_stop(data, own_goal, True, True)
     else:
         return moves.jump_to_face(data, data.ball.location)
Пример #3
0
def get_route_to_ball(data: Data, time_offset=0, look_towards=None):
    dist_step_size = 1410 * 0.5
    max_turn_ang = math.pi * 0.3

    if look_towards is None:
        look_towards = datalibs.get_goal_location(data.enemy, data)

    ball = predict.move_ball(data.ball.copy(), time_offset)

    ball_init_loc = ball.location.flat()
    ball_to_goal = look_towards - ball_init_loc
    if ball_to_goal.flat().length2() == 0:
        ball_to_goal = datalibs.get_goal_location(data.enemy, data) - ball_init_loc

    ball_init_dir = ball_to_goal.flat().normalized() * -1
    car_loc = data.car.location.flat()
    ball_to_car = car_loc - ball_init_loc

    ang = ball_init_dir.ang_to_flat(ball_to_car)

    good_route = abs(ang) < math.pi/2
    if good_route:
        bx = ball_init_loc.x
        by = ball_init_loc.y
        cx = car_loc.x
        cy = car_loc.y
        dx = ball_init_dir.x
        dy = ball_init_dir.y

        t = - (bx*bx - 2*bx*cx + by*by - 2*by*cy + cx*cx + cy*cy) / (2*(bx*dx + by*dy - cx*dx - cy*dy))
        t = min(max(-1400, t), 1400)

        point = ball_init_loc + t * ball_init_dir

        point.x = min(max(-4030, point.x), 4030)
        point.y = min(max(-5090, point.y), 5090)

        return Route([point, ball_init_loc], ball_init_dir, 1, 1410, car_loc, good_route, False)

    else:
        point = car_loc + 700 * ball_init_dir
        return Route([point, ball_init_loc], ball_init_dir, 1, 1410, car_loc, good_route, False)
Пример #4
0
    def execute(self, data):
        car_to_ball = data.ball_when_hit.location - data.car.location

        # Check dodge. A dodge happens after 0.18 sec
        ball_soon = predict.move_ball(data.ball.copy(), 0.15).location
        car_soon = predict.move_ball(datalibs.Ball().set(data.car), 0.25).location
        car_to_ball_soon = ball_soon - car_soon
        # Aim cone was calculated in utility
        if car_to_ball_soon.length() < 240+92 and self.aim_cone.contains_direction(car_to_ball_soon):
            if data.agent.dodge_control.can_dodge(data):
                data.agent.dodge_control.begin_dodge(data, lambda d: d.ball.location, True)
                data.agent.dodge_control.continue_dodge(data)

        goto, goto_time = self.aim_cone.get_goto_point(data, data.ball_when_hit.location)
        dist = car_to_ball.length()

        self.aim_cone.draw(data.renderer, data.ball_when_hit.location, b=0)
        if goto is None or dist < 450:
            # Avoid enemy corners. Just wait
            if data.ball_when_hit.location.y * datalibs.team_sign(data.enemy.team) > 4400 and abs(data.ball_when_hit.location.x) > 900 and not dist < 450:
                wait_point = data.ball_when_hit.location * 0.5  # a point 50% closer to the center of the field
                wait_point = wait_point.lerp(data.ball.location + Vec3(y=datalibs.team_sign(data.car.team) * 3000), 0.5)
                data.renderer.draw_line_3d(data.car.location.tuple(), wait_point.tuple(), self.color(data.renderer))
                return moves.go_towards_point_with_timing(data, wait_point, 1, True)

            if datalibs.is_point_closer_to_goal(data.car.location, data.ball.location, data.car.team):

                # return home
                enemy_goal = datalibs.get_goal_location(data.enemy.team)
                goal_to_ball = (data.ball_when_hit.location - enemy_goal).normalized()
                offset_ball = data.ball_when_hit.location + goal_to_ball * 92
                data.renderer.draw_line_3d(data.car.location.tuple(), offset_ball.tuple(), self.color(data.renderer))
                return moves.go_towards_point(data, offset_ball, False, True)
            else:
                own_goal = datalibs.get_goal_location(data.car.team)
                if moves.consider_dodge(data, own_goal):
                    return data.agent.dodge_control.continue_dodge(data)
                return moves.go_towards_point(data, own_goal, True, False)
        else:
            if moves.consider_dodge(data, goto):
                return data.agent.dodge_control.continue_dodge(data)
            return moves.go_towards_point_with_timing(data, goto, data.time_till_hit * goto_time * 0.95, True)
Пример #5
0
    def utility(self, data):
        team_sign = datalibs.team_sign(data.car.team)
        goal_to_ball = data.ball.location - datalibs.get_goal_location(data.car.team)
        car_to_ball = data.ball.location - data.car.location

        ball_own_half_01 = easing.fix(easing.remap((-1*team_sign) * datalibs.ARENA_LENGTH2, team_sign * datalibs.ARENA_LENGTH2, -0.2, 1.2, data.ball.location.y))

        car_to_ball = data.ball_when_hit.location - data.car.location
        in_position = self.aim_cone.contains_direction(car_to_ball)

        return ball_own_half_01 * in_position
Пример #6
0
    def utility(self, data):
        team_sign = datalibs.team_sign(data.car.team)

        ball_to_goal = datalibs.get_goal_location(data.car.team) - data.ball.location
        ball_vel_g = data.ball.velocity.proj_onto_size(ball_to_goal)
        if ball_vel_g > 0:
            vel_g_01 = easing.fix(ball_vel_g / 700 + 0.36)
        else:
            vel_g_01 = 0

        too_close = ball_to_goal.length2() < 900*900

        hits_goal_prediction = predict.will_ball_hit_goal(data.ball)
        hits_goal = hits_goal_prediction.happens and rlmath.sign(data.ball.velocity.y) == team_sign and hits_goal_prediction.time < 6

        return easing.fix(vel_g_01) or hits_goal or too_close
Пример #7
0
    def execute(self, data):
        car_to_ball = data.ball_when_hit.location - data.car.location
        in_position = self.aim_cone.contains_direction(car_to_ball)
        goto, goto_time = self.aim_cone.get_goto_point(data, data.ball_when_hit.location)

        self.aim_cone.draw(data.renderer, data.ball_when_hit.location, r=0, g=170, b=255)

        if goto is None:
            # go home-ish
            own_goal = datalibs.get_goal_location(data.car.team)
            own_goal = own_goal.lerp(data.ball.location, 0.5)
            if moves.consider_dodge(data, own_goal):
                return data.agent.dodge_control.continue_dodge(data)
            return moves.go_to_and_stop(data, own_goal, True, True)
        else:
            return moves.go_towards_point_with_timing(data, goto, data.time_till_hit * goto_time * 0.95, True)
Пример #8
0
    def utility(self, data):
        team_sign = datalibs.team_sign(data.car.team)

        ball_to_goal = datalibs.get_goal_location(data.car.team) - data.ball.location
        ball_vel_g = data.ball.velocity.proj_onto_size(ball_to_goal)
        if ball_vel_g > 0:
            vel_g_01 = easing.fix(ball_vel_g / 1000 + 0.5)
        else:
            vel_g_01 = easing.fix(0.5 + ball_vel_g / 3000)

        ball_on_my_half_01 = easing.fix(easing.remap((-1*team_sign) * datalibs.ARENA_LENGTH2, team_sign * datalibs.ARENA_LENGTH2, 0, 1.6, data.ball.location.y))
        enemy_on_my_half_01 = easing.fix(easing.remap((-1*team_sign) * datalibs.ARENA_LENGTH2, team_sign * datalibs.ARENA_LENGTH2, 0.5, 1.1, data.ball.location.y))

        enemy_reaches_first = predict.time_till_reach_ball(data.ball, data.enemy) < data.time_till_hit
        enemy_first_01 = 1 if enemy_reaches_first else 0.6

        return easing.fix(ball_on_my_half_01 * enemy_on_my_half_01 * vel_g_01 * enemy_first_01)
Пример #9
0
    def execute(self, data):
        self.ball_to_goal_right = self.own_goal_right - data.ball_when_hit.location
        self.ball_to_goal_left = self.own_goal_left - data.ball_when_hit.location
        self.aim_cone = route.AimCone(self.ball_to_goal_left.ang(), self.ball_to_goal_right.ang())
        car_to_ball = data.ball_when_hit.location - data.car.location
        in_position = self.aim_cone.contains_direction(car_to_ball)
        goto, goto_time = self.aim_cone.get_goto_point(data, data.ball_when_hit.location)

        self.aim_cone.draw(data.renderer, data.ball_when_hit.location, r=220, g=0, b=110)

        if goto is None or data.car.location.dist(data.ball.location) > 2000:
            # go home-ish
            own_goal = datalibs.get_goal_location(data.car.team)
            own_goal = own_goal.lerp(data.ball.location, 0.5)
            if moves.consider_dodge(data, own_goal):
                return data.agent.dodge_control.continue_dodge(data)
            return moves.go_to_and_stop(data, own_goal, True, True)
        else:
            if moves.consider_dodge(data, goto):
                return data.agent.dodge_control.continue_dodge(data)
            return moves.go_towards_point_with_timing(data, goto, data.time_till_hit * goto_time * 0.95, True)
Пример #10
0
 def get_point_of_interest(self, data):
     return datalibs.get_goal_location(data.car.team)