Example #1
0
    def __init__(self, agent, packet: GameTickPacket, should_render=False):
        self.agent = agent
        if should_render:
            self.renderer = agent.renderer
        else:
            self.renderer = render.FakeRenderer()
        self.packet = packet
        self.ball = Ball().set_game_ball(packet.game_ball)

        self.car = Car(packet.game_cars[agent.index])
        self.enemy = Car(packet.game_cars[1 - agent.index])

        self.car.set_ball_dependent_variables(self.ball)
        self.enemy.set_ball_dependent_variables(self.ball)

        self.__decide_possession()

        # predictions
        self.time_till_hit = predict.time_till_reach_ball(self.ball, self.car)
        self.ball_when_hit = predict.move_ball(self.ball.copy(),
                                               self.time_till_hit)
        if self.ball_when_hit.location.z > 100:
            time_till_ground = predict.time_of_arrival_at_height(
                self.ball_when_hit, 100).time
            self.ball_when_hit = predict.move_ball(self.ball_when_hit,
                                                   time_till_ground)
            self.time_till_hit += time_till_ground
Example #2
0
    def execute(self, bot):
        car = bot.info.my_car
        shoot_controls = bot.shoot.with_aiming(
            bot, self.aim_cone,
            predict.time_till_reach_ball(bot.info.my_car, bot.info.ball))
        hit_pos = bot.shoot.ball_when_hit.pos

        if bot.do_rendering:
            self.aim_cone.draw(bot, hit_pos, r=0, g=170, b=255)

        if bot.shoot.can_shoot:
            bot.controls = shoot_controls

            if bot.shoot.using_curve and bot.do_rendering:
                render.draw_bezier(bot,
                                   [car.pos, bot.shoot.curve_point, hit_pos])

        else:
            # go home-ish
            own_goal = lerp(bot.info.own_goal, bot.info.ball.pos, 0.5)
            bot.controls = bot.drive.go_towards_point(bot,
                                                      own_goal,
                                                      target_vel=1460,
                                                      slide=True,
                                                      boost=True,
                                                      can_keep_speed=True)
Example #3
0
    def utility(self, bot):
        team_sign = bot.info.team_sign

        length = team_sign * FIELD_LENGTH / 2
        ball_own_half_01 = clip01(remap(-length, length, -0.2, 1.2, bot.info.ball.pos[Y]))

        reachable_ball = predict.ball_predict(bot, predict.time_till_reach_ball(bot.info.my_car, bot.info.ball))
        car_to_ball = reachable_ball.pos - bot.info.my_car.pos
        in_position = self.aim_cone.contains_direction(car_to_ball, math.pi / 8)

        return ball_own_half_01 * in_position
Example #4
0
    def utility(self, bot):
        ball_soon = predict.ball_predict(bot, 1)

        arena_length2 = bot.info.team_sign * FIELD_LENGTH / 2
        own_half_01 = clip01(remap(arena_length2, -arena_length2, 0.0, 1.1, ball_soon.pos[Y]))

        reachable_ball = predict.ball_predict(bot, predict.time_till_reach_ball(bot.info.my_car, bot.info.ball))
        self.ball_to_goal_right = bot.info.enemy_goal_right - reachable_ball.pos
        self.ball_to_goal_left = bot.info.enemy_goal_left - reachable_ball.pos
        self.aim_cone = AimCone(self.ball_to_goal_right, self.ball_to_goal_left)
        car_to_ball = reachable_ball.pos - bot.info.my_car.pos
        in_position = self.aim_cone.contains_direction(car_to_ball)

        return clip01(own_half_01 + 0.1 * in_position)
Example #5
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)
Example #6
0
    def execute(self, bot):

        car = bot.info.my_car
        ball = bot.info.ball

        shoot_controls = bot.shoot.with_aiming(bot, self.aim_cone, predict.time_till_reach_ball(car, ball))
        if bot.do_rendering:
            self.aim_cone.draw(bot, bot.shoot.ball_when_hit.pos, b=0)

        hit_pos = bot.shoot.ball_when_hit.pos
        dist = norm(car.pos - hit_pos)
        closest_enemy, enemy_dist = bot.info.closest_enemy(0.5 * (hit_pos + ball.pos))

        if not bot.shoot.can_shoot and is_closer_to_goal_than(car.pos, hit_pos, bot.info.team):
            # Can't shoot but or at least on the right side: Chase

            goal_to_ball = normalize(hit_pos - bot.info.enemy_goal)
            offset_ball = hit_pos + goal_to_ball * BALL_RADIUS * 0.9
            bot.controls = bot.drive.go_towards_point(bot, offset_ball, target_vel=2200, slide=False, boost=True)

            if bot.do_rendering:
                bot.renderer.draw_line_3d(car.pos, offset_ball, bot.renderer.yellow())

        elif not bot.shoot.aim_is_ok and hit_pos[Y] * -bot.info.team_sign > 4350 and abs(hit_pos[X]) > 900 and not dist < 450:
            # hit_pos is an enemy corner and we are not close: Avoid enemy corners and just wait

            enemy_to_ball = normalize(hit_pos - closest_enemy.pos)
            wait_point = hit_pos + enemy_to_ball * enemy_dist  # a point 50% closer to the center of the field
            wait_point = lerp(wait_point, ball.pos + vec3(0, bot.info.team_sign * 3000, 0), 0.5)
            bot.controls = bot.drive.go_towards_point(bot, wait_point, norm(car.pos - wait_point), slide=False, boost=False, can_keep_speed=True, can_dodge=False)

            if bot.do_rendering:
                bot.renderer.draw_line_3d(car.pos, wait_point, bot.renderer.yellow())

        elif not bot.shoot.can_shoot:
            # return home
            bot.controls = bot.drive.go_home(bot)

        else:
            # Shoot !
            bot.controls = shoot_controls

            if bot.shoot.using_curve and bot.do_rendering:
                render.draw_bezier(bot, [car.pos, bot.shoot.curve_point, hit_pos])
Example #7
0
    def execute(self, bot):

        car = bot.info.my_car
        ball = bot.info.ball

        hits_goal_prediction = predict.will_ball_hit_goal(bot)
        reach_time = clip(predict.time_till_reach_ball(car, ball), 0, hits_goal_prediction.time - 0.5)
        reachable_ball = predict.ball_predict(bot, reach_time)
        self.ball_to_goal_right = self.own_goal_right - reachable_ball.pos
        self.ball_to_goal_left = self.own_goal_left - reachable_ball.pos
        self.aim_cone = AimCone(self.ball_to_goal_left, self.ball_to_goal_right)

        self.aim_cone.draw(bot, reachable_ball.pos, r=200, g=0, b=160)

        shoot_controls = bot.shoot.with_aiming(bot, self.aim_cone, reach_time)

        if not bot.shoot.can_shoot:
            # Go home
            bot.controls = bot.drive.go_home(bot)
        else:
            bot.controls = shoot_controls