コード例 #1
0
    def run(self, agent):
        if self.start_time is None:
            self.start_time = agent.time

        time_elapsed = round(agent.time - self.start_time, 5)

        if (0.0 <= time_elapsed
                and time_elapsed <= 0.0083) or (2.05 <= time_elapsed
                                                and time_elapsed <= 2.6167):
            agent.controller.steer = agent.controller.yaw = 1

        if (0.3333 <= time_elapsed and time_elapsed <= 0.4167) or (
                0.475 <= time_elapsed and time_elapsed <= 0.6417) or (
                    2.0917 <= time_elapsed and time_elapsed <= 2.1667) or (
                        2.2167 <= time_elapsed and time_elapsed <= 2.4083):
            agent.controller.jump = True

        if (0.0 <= time_elapsed
                and time_elapsed <= 0.3917) or (1.625 <= time_elapsed
                                                and time_elapsed <= 2.45):
            agent.controller.boost = True

        if (0.0 <= time_elapsed
                and time_elapsed <= 0.7667) or (1.5917 <= time_elapsed
                                                and time_elapsed <= 2.575):
            agent.controller.throttle = 1
            agent.controller.pitch = -1

        if time_elapsed > 2.6167:
            agent.pop()
            agent.push(recovery())
            agent.kickoff_done = True
コード例 #2
0
    def run(self, agent):
        if self.start_time == None:
            self.start_time = agent.time

        time_elapsed = round(agent.time - self.start_time, 5)

        if (0 <= time_elapsed
                and time_elapsed <= 0.775) or (1.7 <= time_elapsed
                                               and time_elapsed <= 2.9333):
            agent.controller.throttle = 1
            agent.controller.pitch = -1

        if (0.55 <= time_elapsed and time_elapsed <= 0.7417) or (
                1.7917 <= time_elapsed and time_elapsed <= 1.925) or (
                    2.45 <= time_elapsed and time_elapsed <= 2.5333) or (
                        2.5917 <= time_elapsed and time_elapsed <= 2.7583):
            agent.controller.jump = True

        if (0.9583 <= time_elapsed and time_elapsed <= 1.3):
            agent.controller.throttle = -1
            agent.controller.pitch = 1

        if (0 <= time_elapsed and time_elapsed <= 1.1167) or (
                2.025 <= time_elapsed and time_elapsed <= 2.125) or (
                    2.1833 <= time_elapsed and time_elapsed <= 2.2917) or (
                        2.35 <= time_elapsed and time_elapsed <= 2.4417):
            agent.controller.boost = True

        if time_elapsed > 2.9333:
            agent.pop()
            agent.push(recovery())
            agent.kickoff_done = True
コード例 #3
0
ファイル: main.py プロジェクト: aejester/HeatSeekingMissile
    def run(self):
        # NOTE This method is ran every tick

        # If the kickoff isn't done
        if not self.kickoff_done:
            # If the stack is clear
            if self.is_clear():
                # Push a generic kickoff to the stack
                # TODO make kickoff routines for each of the 5 kickoffs positions
                self.push(routines.generic_kickoff())

            # we don't want to do anything else during our kickoff
            return

        # If the stack if clear and we're in the air
        if self.is_clear() and self.me.airborne:
            # Recover - This routine supports floor, wall, and ceiling recoveries, as well as recovering towards a target
            self.push(routines.recovery())

            # we've made our decision and we don't want to run anything else
            return

        # If we have less than 36 boost
        # TODO this bot will go for boost no matter what - this is AWFUL, especially in a 1v1!
        if self.me.boost < 36:
            # If the stack is clear
            if self.is_clear():
                # Get a list of all of the large, active boosts
                boosts = tuple(boost for boost in self.boosts
                               if boost.active and boost.large)

                # if there's at least one large and active boost
                if len(boosts) > 0:
                    # Get the closest boost
                    closest_boost = min(boosts,
                                        key=lambda boost: boost.location.dist(
                                            self.me.location))
                    # Goto the nearest boost
                    self.push(routines.goto_boost(closest_boost))

            # we've made our decision and we don't want to run anything else
            if not self.is_clear():
                return

        # if the stack is clear, then run the following - otherwise, if the stack isn't empty, then look for a shot every 4th tick while the other routine is running
        if self.is_clear() or self.odd_tick == 0:
            shot = None

            # TODO we might miss the net, even when using a target - make a pair of targets that are small than the goal so we have a better chance of scoring!
            # If the ball is on the enemy's side of the field, or slightly on our side
            if self.ball.location.y * utils.side(self.team) < 640:
                # Find a shot, on target - double_jump, jump_shot, and ground_shot  are automatically disabled if we're airborne
                shot = tools.find_shot(self, self.foe_goal_shot)

            # TODO Using an anti-target here could be cool - do to this, pass in a target tuple that's (right_target, left_target) (instead of (left, right)) into tools.find_shot (NOT tools.find_any_shot)
            # TODO When possible, we might want to take a little bit more time to shot the ball anywhere in the opponent's end - this target should probably be REALLY LONG AND HIGH!
            # If we're behind the ball and we couldn't find a shot on target
            if shot is None and self.ball.location.y * utils.side(
                    self.team) < self.me.location.y * utils.side(self.team):
                # Find a shot, but without a target - double_jump, jump_shot, and ground_shot are automatically disabled if we're airborne
                shot = tools.find_any_shot(self)

            # If we found a shot
            if shot is not None:
                # If the stack is clear
                if self.is_clear():
                    # Shoot
                    self.push(shot)
                # If the stack isn't clear
                else:
                    # Get the current shot's name (ex jump_shot, double_jump, ground_shot or Aerial) as a string
                    current_shot_name = self.stack[0].__class__.__name__
                    # Get the new shot's name as a string
                    new_shot_name = shot.__class__.__name__

                    # If the shots are the same type
                    if new_shot_name is current_shot_name:
                        # Update the existing shot with the new information
                        self.stack[0].update(shot)
                    # If the shots are of different types
                    else:
                        # Clear the stack
                        self.clear()
                        # Shoot
                        self.push(shot)

                # we've made our decision and we don't want to run anything else
                return

        # TODO this setup is far from ideal - a custom shadow/retreat routine is probably best for the bot...
        # Make sure to put custom routines in a separate file from VirxERLU routines, so you can easily update VirxERLU to newer versions.
        # If the stack is still clear
        if self.is_clear():
            # If ball is in our half
            if self.ball.location.y * utils.side(self.team) > 640:
                retreat_routine = routines.retreat()
                # Check if the retreat routine is viable
                if retreat_routine.is_viable(self):
                    # Retreat back to the net
                    self.push(retreat_routine)
            # If the ball isn't in our half
            else:
                shadow_routine = routines.shadow()
                # Check if the shadow routine is viable
                if shadow_routine.is_viable(self):
                    # Shadow
                    self.push(shadow_routine)
コード例 #4
0
 def recover_from_air(self):
     self.clear()
     self.push(recovery(self.friend_goal.location))
コード例 #5
0
ファイル: VirxEB.py プロジェクト: RLBot/RLBotPack
    def run(self):
        # predictions
        self.update_predictions()

        # act on the predictions
        if not self.kickoff_done:
            if self.is_clear():
                if len(self.friends) > 0:
                    if almost_equals(self.predictions['team_to_ball'][0],
                                     self.predictions['self_to_ball'], 5):
                        self.offensive_kickoff()
                    elif almost_equals(self.predictions['team_to_ball'][-1],
                                       self.predictions['self_to_ball'], 5):
                        self.defensive_kickoff()
                elif len(self.foes) == 0 or almost_equals(
                        self.predictions['closest_enemy'],
                        self.predictions['self_to_ball'], 10):
                    self.offensive_kickoff()
                else:
                    self.defensive_kickoff()
            return

        if self.can_shoot is None:
            self.dbg_3d("Can shoot: 0")
        else:
            self.dbg_3d(
                f"Can shoot: {round(3 - (self.time - self.can_shoot), 2)}")

        enemy_intercept_location = self.ball_prediction_struct.slices[
            self.future_ball_location_slice].physics.location
        enemy_intercept_location = Vector(enemy_intercept_location.x,
                                          enemy_intercept_location.y,
                                          enemy_intercept_location.z)
        if self.predictions['enemy_time_to_ball'] != 7:
            self.sphere(enemy_intercept_location, 92.75, self.renderer.red())

        self_intercept_location = self.ball_prediction_struct.slices[
            self.min_intercept_slice].physics.location
        self_intercept_location = Vector(self_intercept_location.x,
                                         self_intercept_location.y,
                                         self_intercept_location.z)
        if self.predictions['self_min_time_to_ball'] != 7:
            self.sphere(self_intercept_location, 92.75, self.renderer.green())

        if side(self.team) * enemy_intercept_location.y >= self.defense_switch[
                self.playstyle] or self.predictions['own_goal']:
            for shot in self.defensive_shots:
                self.line(*shot, self.renderer.team_color(alt_color=True))

            self.dbg_3d("(Defending)")

            if self.predictions['enemy_time_to_ball'] > self.predictions[
                    'self_min_time_to_ball'] + (
                        3 if self.shooting else
                        1) and self.me.boost < 36 and not self.is_clear(
                        ) and self.get_stack_name() == 'goto_boost':
                return

            ball_loc = self_intercept_location * side(self.team)
            self_loc = self.me.location * side(self.team)

            # This is a list of all tm8s that are onside
            team_to_ball = [
                car.location.flat_dist(self.ball.location)
                for car in self.friends
                if car.location.y * side(self.team) >= ball_loc.y +
                95 and abs(car.location.x) < abs(self.ball.location.x) - 320
            ]
            self_to_ball = self.me.location.flat_dist(self.ball.location)
            team_to_ball.append(self_to_ball)
            team_to_ball.sort()

            if len(team_to_ball) == 1 or team_to_ball[math.ceil(
                    len(team_to_ball) / 2)] + 10 > self_to_ball:
                self.can_shoot = None

            if self.can_shoot is None and (self.is_clear()
                                           or self.odd_tick == 0):
                if self_loc.y > ball_loc.y + 95 and self.smart_shot(
                        self.best_shot, cap=4):
                    return

                if ball_loc.y - self_loc.y > (
                        ball_loc.x - self_loc.x
                ) * 1.5 and (
                        self.predictions['own_goal'] or
                    (len(team_to_ball) > 1 and team_to_ball[math.ceil(
                        len(team_to_ball) / 2)] + 10 > self_to_ball) or
                    (len(team_to_ball) == 1 and self_to_ball < 2560) or
                    (abs(ball_loc.x) < 900 and ball_loc.y > 1280)
                ) and team_to_ball[0] is self_to_ball and self.smart_shot(
                        self.anti_shot, weight=self.max_shot_weight - 3,
                        cap=4):
                    return

                if self_loc.y > ball_loc.y + 95:
                    for i, shot in enumerate(
                            self.defensive_shots
                            if self.predictions['self_min_time_to_ball'] *
                            2 < self.predictions['enemy_time_to_ball'] else
                            self.defensive_shots[1:]):
                        shot_weight = get_weight(self, index=i)

                        if self.shooting and shot_weight < self.shot_weight:
                            break

                        shot = self.get_shot(shot, weight=shot_weight, cap=4)

                        if shot is not None:
                            if self.shooting:
                                self.upgrade_shot(shot)
                            else:
                                self.shoot_from(shot, clear_on_valid=True)
                            return

                    if self.smart_shot(self.anti_shot,
                                       weight=self.max_shot_weight - 3,
                                       cap=3):
                        return

            if not self.me.airborne and (not self.shooting
                                         or self.shot_weight == -1):
                if self.predictions['enemy_time_to_ball'] > self.predictions[
                        'self_min_time_to_ball'] + (
                            3 if self.shooting else
                            1) and self.me.boost < 36 and (
                                self.is_clear()
                                or self.get_stack_name() != 'goto_boost'
                            ) and self.goto_nearest_boost(clear_on_valid=True):
                    return

                if not self.predictions[
                        'own_goal'] and self_loc.y <= ball_loc.y - 50 and not self.is_clear(
                        ) and self.get_stack_name() == 'goto_boost' and abs(
                            ball_loc.x) > 1024 and self.backcheck(
                                clear_on_valid=True):
                    return

                if self.is_clear() and not self.backcheck():
                    face_target_routine = face_target(ball=True)
                    ball_f = face_target_routine.get_ball_target(self)
                    if ball_f.y * side(self.team) > -3840 and abs(
                            Vector(x=1).angle2D(self.me.local_location(ball_f))
                    ) >= 1 and self.me.velocity.magnitude() < 100:
                        self.push(face_target_routine)
                        return

            return

        if self.me.airborne and self.is_clear():
            self.push(recovery())

        if not self.is_clear() and self.get_stack_name(
        ) == "short_shot" and self.me.location.y * side(
                self.team) < self.ball.location.y * side(self.team):
            self.clear()

        self.playstyles_switch[self.playstyle]()
        ""
コード例 #6
0
 def recover_from_air(self):
     if self.is_clear() and self.me.airborne:
         self.push(recovery(self.friend_goal.location))
         return True
     return False