示例#1
0
    def execute(self, bot):
        if self.aerialturn is None:
            self.aerialturn = AerialTurn(bot.info.my_car)

        self.aerialturn.step(0.01666)
        self.aerialturn.controls.throttle = 1
        bot.controls = self.aerialturn.controls
        self.finished = self.aerialturn.finished
示例#2
0
    def step(self, tick):
        self.Ginfo.read_packet(self.agent.packet)
        action = AerialTurn(self.Ginfo.my_car)
        action.step(tick)
        action.controls.throttle = 1

        self.expired = action.finished
        self.expired = self.car.has_wheel_contact

        return action.controls
示例#3
0
    def execute(self, bot):
        bot.renderer.draw_string_3d(bot.info.my_car.pos, 1, 1, "Recovery",
                                    bot.renderer.blue())

        if self.aerial_turn == None:
            self.aerial_turn = AerialTurn(bot.info.my_car)

        self.aerial_turn.step(0.016666)
        bot.controls = self.aerial_turn.controls
        bot.controls.throttle = 1
def aerial_face(car, dir, up=vec3(0, 0, 1)):
    pos = car.pos
    target = look_at(vec3(dir[0], dir[1], dir[2]), up)
    action = AerialTurn(car, target)
    action.step(1 / 60)
    pitch = action.controls.pitch
    roll = action.controls.roll
    yaw = action.controls.yaw

    return pitch, roll, yaw
示例#5
0
    def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        self.info.read_packet(packet)
        self.controls = SimpleControllerState()

        if self.timer < 0.05:

            position = Vector3(random.uniform(-4000, 4000),
                               random.uniform(-3000, 3000),
                               random.uniform(500, 2000))

            velocity = Vector3(random.uniform(-1500, 1500),
                               random.uniform(-1500, 1500),
                               random.uniform(-1000, -500))

            rotation = Rotator(random.uniform(-1.5, 1.5),
                               random.uniform(-1.5, 1.5),
                               random.uniform(-1.5, 1.5))

            angular_velocity = Vector3(random.uniform(-3.0, 3.0),
                                       random.uniform(-3.0, 3.0),
                                       random.uniform(-3.0, 3.0))

            car_state = CarState(
                physics=Physics(location=position,
                                velocity=velocity,
                                rotation=rotation,
                                angular_velocity=angular_velocity))

            self.set_game_state(GameState(cars={self.index: car_state}))

        if self.timer > 0.10:

            if self.action == None:
                self.action = AerialTurn(self.info.my_car)

            self.renderer.begin_rendering()
            red = self.renderer.create_color(255, 255, 30, 30)
            self.renderer.draw_polyline_3d(self.action.trajectory, red)
            self.renderer.end_rendering()

            self.action.step(1.0 / 60.0)
            self.controls = self.action.controls

            self.timer += 1.0 / 60.0
            if self.action.finished or self.timer > 5.0:
                print("target:\n", self.action.target)
                print("theta:\n", self.action.car.theta)
                print()
                self.timer = 0.0
                self.action = None

        self.timer += 1.0 / 60.0
        return self.controls
示例#6
0
class RecoverPlan:
    def __init__(self):
        self.finished = False
        self.aerialturn = None

    def execute(self, bot):
        if self.aerialturn is None:
            self.aerialturn = AerialTurn(bot.info.my_car)

        self.aerialturn.step(0.01666)
        self.aerialturn.controls.throttle = 1
        bot.controls = self.aerialturn.controls
        self.finished = self.aerialturn.finished
示例#7
0
 def set_mechanics(self):
     if self.drive is None:
         self.drive = Drive(self.info.my_car, self.info.ball.pos, 1399)
     if self.catching is None:
         self.catching = Catching(self.info.my_car, self.info.ball.pos,
                                  1399)
     if self.recovery is None:
         self.recovery = AerialTurn(self.info.my_car)
     if self.dodge is None:
         self.dodge = AirDodge(self.info.my_car, 0.25, self.info.ball.pos)
     if self.dribble is None:
         self.dribble = Dribbling(self.info.my_car, self.info.ball,
                                  self.info.their_goal)
示例#8
0
    def step(self,
             car: Car,
             target: vec3,
             dt: float = 0.01667) -> SimpleControllerState:
        super(FaceVectorRLU, self).step(car, target)
        # up = vec3(*[self.car.theta[i, 2] for i in range(3)])

        target_rotation = look_at(self.target)
        self.action = AerialTurn(car, target_rotation)

        self.action.step(dt)
        self.controls = self.action.controls

        self.car.last_input.pitch = self.controls.pitch
        self.car.last_input.yaw = self.controls.yaw
        self.car.last_input.roll = self.controls.roll

        return self.controls
示例#9
0
class FixOrientation:
    def __init__(self, bot):
        self.aerial_turn = None

    def utility(self, bot):
        return not bot.info.my_car.on_ground

    def execute(self, bot):
        bot.renderer.draw_string_3d(bot.info.my_car.pos, 1, 1, "Recovery",
                                    bot.renderer.blue())

        if self.aerial_turn == None:
            self.aerial_turn = AerialTurn(bot.info.my_car)

        self.aerial_turn.step(0.016666)
        bot.controls = self.aerial_turn.controls
        bot.controls.throttle = 1

    def reset(self):
        self.aerial_turn = None
示例#10
0
    def get_output(self, packet):
        self.info.read_packet(packet)

        #additional processing not done by RLU
        self.kickoff_pause  = packet.game_info.is_kickoff_pause
        self.round_active   = packet.game_info.is_round_active
        self.dt             = self.info.time - self.last_time
        self.last_time      = self.info.time
        self.last_touch     = packet.game_ball.latest_touch.player_name
        
        #trashtalk
        if packet.game_cars[self.index].score_info.goals == self.goals + 1:
            self.send_quick_chat(QuickChats.CHAT_EVERYONE, QuickChats.Reactions_Calculated)
            
        self.goals          = packet.game_cars[self.index].score_info.goals

        #resets controls each tick
        self.controls = SimpleControllerState()

        #choose state
        if not self.round_active:
            self.state = None
        elif not self.state == "kickoff":
            if self.kickoff_pause:
                self.kickoff_pos    = None
                self.action         = None
                self.timer          = 0.0
                self.state          = "kickoff"
        
            elif not self.info.my_car.on_ground and not isinstance(self.action, AirDodge):
                self.state          = "recovery"
                self.action         = self.action = AerialTurn(self.info.my_car)

            elif norm(self.info.my_goal.center - self.info.my_car.pos) > norm(self.info.my_goal.center - self.info.ball.pos) + self.def_extra_dist:
                self.action         = None
                self.target_speed   = 2300
                self.state          = "defence"
		
                if self.team == 0:
                    sign = -1
                else:
                    sign = 1
                
                #temporary 2v2 for Cow
                if len(self.info.teammates) > 0:
                    if self.info.ball.pos[1] > 0:
                        self.target = vec3(3000,sign*4000,0)
                    else:
                        self.target = vec3(-3000,sign*4000,0)
                else:
                    self.target = vec3(0,sign*4000,0)

            elif self.info.my_car.pos[1] > 5120 or self.info.my_car.pos[1] < -5120:
                self.target         = vec3(0,5000,0) if self.info.my_car.pos[1] > 5120 else vec3(0,-5000,0)
                self.action         = self.action = Drive(self.info.my_car,self.target,1000)
                self.state          = "goal escape"

            elif self.state == None:
                self.action         = None
                self.target         = None
                self.target_speed   = 2300
                self.state          = "offence"


        #kickoff state
        if self.state == "kickoff":
            Kickoff.kickoff(self)

            #exit kickoff state
            if self.timer >= 2.6 or self.last_touch != '':
                self.state  = None
                self.action = None

        #recovery state
        elif self.state == "recovery":
            self.action.step(self.dt)
            self.controls           = self.action.controls
            self.controls.throttle  = 1.0
            
            #exit recovery state
            if self.info.my_car.on_ground == True:
                self.state  = None
                self.action = None


        #defence state and offence state
        elif self.state == "defence" or self.state == "offence":  
            #select target
            if self.target == None:
                #large boost
                if self.info.my_car.boost <= self.low_boost and norm(self.info.my_car.pos - self.info.ball.pos) > self.max_ball_dist:
                    active_pads = []
                    for pad in self.info.boost_pads:
                        if pad.is_active:
                            active_pads.append(pad)

                    if len(active_pads) != 0:
                        closest_pad = active_pads[0]
                        for pad in active_pads:
                            if norm(pad.pos - self.info.ball.pos) < norm(closest_pad.pos - self.info.ball.pos):
                                closest_pad = pad
                        self.target = closest_pad.pos
                    else:
                        self.target = self.info.ball.pos

                #ball        
                else:
                    self.target = self.info.ball.pos

            forward_target  = dot(self.target - self.info.my_car.pos, self.info.my_car.theta)[0]
            right_target    = dot(self.target - self.info.my_car.pos, self.info.my_car.theta)[1]
            angle_to_target = math.atan2(right_target, forward_target)

            forward_goal    = dot(self.info.their_goal.center - self.info.my_car.pos, self.info.my_car.theta)[0]
            right_goal      = dot(self.info.their_goal.center - self.info.my_car.pos, self.info.my_car.theta)[1]
            angle_to_goal   = math.atan2(right_goal, forward_goal)

            #select maneuver
            if not isinstance(self.action, AirDodge):
                #shooting
                if norm(self.info.ball.pos - self.info.my_car.pos) < self.dodge_dist and (angle_to_target - (math.pi/10.0) <= angle_to_goal <= angle_to_target + (math.pi/10.0)): 
                    self.action = AirDodge(self.info.my_car,0.2,self.info.their_goal.center)
                    self.timer  = 0.0
                #dodging
                elif (-math.pi/24.0) <= angle_to_target <= (math.pi/24.0) and norm(self.info.my_car.vel) > 700 and norm(self.info.ball.pos - self.info.my_car.pos) > 1000 and not self.state == "defence":
                    self.action = AirDodge(self.info.my_car,0.2,self.target)
                    self.timer  = 0.0
                #Drive
                else:
                    self.action = Drive(self.info.my_car,self.target,self.target_speed)
                
            #exit AirDodge
            else:
                self.timer += self.dt
                if self.timer >= 0.5:
                    self.action = None
 
            #Drive
            if isinstance(self.action, Drive):
                speed = norm(self.info.my_car.vel)
                r = -6.901E-11 * speed**4 + 2.1815E-07 * speed**3 - 5.4437E-06 * speed**2 + 0.12496671 * speed + 157

                #handbrake
                self.drift = False
                if (math.pi/2.0) <= angle_to_target or angle_to_target <= (-math.pi/2.0):
                    self.drift = True

                #target speed 
                elif (norm(self.target - (self.info.my_car.pos + dot(self.info.my_car.theta,vec3(0,r,0)))) < r or norm(self.target - (self.info.my_car.pos + dot(self.info.my_car.theta,vec3(0,-r,0)))) < r) and not self.target_speed < self.min_target_s:
                    self.target_speed += -50
                    self.action = Drive(self.info.my_car,self.target,self.target_speed)
                elif self.target_speed < 1800:
                    self.target_speed += 50
                    self.action = Drive(self.info.my_car,self.target,self.target_speed)

            #maneuver tick
            if self.action != None:
                self.action.step(self.dt)
                self.controls   = self.action.controls
                self.controls.handbrake = self.drift

            #exit either state
            if (self.state == "defence" and norm(self.info.my_goal.center - self.info.my_car.pos) < norm(self.info.my_goal.center - self.info.ball.pos)) or (norm(self.target - self.info.my_car.pos) < self.target_range):
                self.state = None


        #goal escape state
        if self.state == "goal escape":
            self.action.step(self.dt)
            self.controls   = self.action.controls

            #exit goal escape state
            if not (self.info.my_car.pos[1] > 5120 or self.info.my_car.pos[1] < -5120):
                self.state  = None
                self.action = None

        if 'win32gui' in sys.modules:
            #finding the size of the Rocket League window
            def callback(hwnd, win_rect):
                if "Rocket League" in win32gui.GetWindowText(hwnd):
                    rect = win32gui.GetWindowRect(hwnd)
                    win_rect[0] = rect[0]
                    win_rect[1] = rect[1]
                    win_rect[2] = rect[2] - rect[0]
                    win_rect[3] = rect[3] - rect[1]

            self.RLwindow = [0] * 4
            win32gui.EnumWindows(callback, self.RLwindow)

        #Rendering
        Render.debug(self)
        Render.turn_circles(self)
        if not self.target == None:
            Render.target(self)
        

        return self.controls
示例#11
0
class hypebot(BaseAgent):
    def __init__(self, name, team, index):
        super().__init__(name, team, index)
        self.name = name
        self.team = team
        self.index = index
        self.defending = False
        self.info = None
        self.bounces = []
        self.drive = None
        self.catching = None
        self.dodge = None
        self.recovery = None
        self.dribble = None
        self.controls = SimpleControllerState()
        self.kickoff = False
        self.inFrontOfBall = False
        self.kickoffStart = None
        self.step = "Catching"
        self.time = 0
        self.FPS = 1 / 120
        self.p_s = 0.
        self.kickoffTime = 0

    def initialize_agent(self):
        self.info = GameInfo(self.index, self.team, self.get_field_info())

    def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        if packet.game_info.seconds_elapsed - self.time > 0:
            self.FPS = packet.game_info.seconds_elapsed - self.time
        self.time = packet.game_info.seconds_elapsed
        self.info.read_packet(packet)
        self.predict()
        self.set_mechanics()
        prev_kickoff = self.kickoff
        self.kickoff = packet.game_info.is_kickoff_pause
        self.defending = self.should_defending()
        if self.kickoff and not prev_kickoff:
            initKickOff(self)
        if self.kickoff or self.step == "Dodge2":
            kickOff(self)
        else:
            self.get_controls()
        self.render_string(str(self.step))
        if not packet.game_info.is_round_active:
            self.controls.steer = 0
        return self.controls

    def predict(self):
        self.bounces = []
        ball_prediction = self.get_ball_prediction_struct()
        for i in range(ball_prediction.num_slices):
            location = vec3(ball_prediction.slices[i].physics.location.x,
                            ball_prediction.slices[i].physics.location.y,
                            ball_prediction.slices[i].physics.location.z)
            prev_ang_vel = ball_prediction.slices[i -
                                                  1].physics.angular_velocity
            prev_normalized_ang_vel = normalize(
                vec3(prev_ang_vel.x, prev_ang_vel.y, prev_ang_vel.z))
            current_ang_vel = ball_prediction.slices[
                i].physics.angular_velocity
            current_normalized_ang_vel = normalize(
                vec3(current_ang_vel.x, current_ang_vel.y, current_ang_vel.z))
            if prev_normalized_ang_vel != current_normalized_ang_vel and location[
                    2] < 125:
                self.bounces.append((location, i * 1 / 60))

    def set_mechanics(self):
        if self.drive is None:
            self.drive = Drive(self.info.my_car, self.info.ball.pos, 1399)
        if self.catching is None:
            self.catching = Catching(self.info.my_car, self.info.ball.pos,
                                     1399)
        if self.recovery is None:
            self.recovery = AerialTurn(self.info.my_car)
        if self.dodge is None:
            self.dodge = AirDodge(self.info.my_car, 0.25, self.info.ball.pos)
        if self.dribble is None:
            self.dribble = Dribbling(self.info.my_car, self.info.ball,
                                     self.info.their_goal)

    def get_controls(self):
        if self.step == "Steer" or self.step == "Dodge2":
            self.step = "Catching"
        if self.step == "Catching":
            target = get_bounce(self)
            if target is None:
                self.step = "Defending"
            else:
                self.catching.target_pos = target[0]
                self.catching.target_speed = (distance_2d(
                    self.info.my_car.pos, target[0]) + 50) / target[1]
                self.catching.step(self.FPS)
                self.controls = self.catching.controls
                ball = self.info.ball
                car = self.info.my_car
                if distance_2d(ball.pos,
                               car.pos) < 150 and 65 < abs(ball.pos[2] -
                                                           car.pos[2]) < 127:
                    self.step = "Dribbling"
                    self.dribble = Dribbling(self.info.my_car, self.info.ball,
                                             self.info.their_goal)
                if self.defending:
                    self.step = "Defending"
                if not self.info.my_car.on_ground:
                    self.step = "Recovery"
                ball = self.info.ball
                if abs(ball.vel[2]) < 100 and sign(
                        self.team) * ball.vel[1] < 0 and sign(
                            self.team) * ball.pos[1] < 0:
                    self.step = "Shooting"
        elif self.step == "Dribbling":
            self.dribble.step(self.FPS)
            self.controls = self.dribble.controls
            ball = self.info.ball
            car = self.info.my_car
            bot_to_opponent = self.info.opponents[0].pos - self.info.my_car.pos
            local_bot_to_target = dot(bot_to_opponent, self.info.my_car.theta)
            angle_front_to_target = math.atan2(local_bot_to_target[1],
                                               local_bot_to_target[0])
            opponent_is_near = norm(vec2(bot_to_opponent)) < 2000
            opponent_is_in_the_way = math.radians(
                -10) < angle_front_to_target < math.radians(10)
            if not (distance_2d(ball.pos, car.pos) < 150
                    and 65 < abs(ball.pos[2] - car.pos[2]) < 127):
                self.step = "Catching"
            if self.defending:
                self.step = "Defending"
            if opponent_is_near and opponent_is_in_the_way:
                self.step = "Dodge"
                self.dodge = AirDodge(self.info.my_car, 0.25,
                                      self.info.their_goal.center)
            if not self.info.my_car.on_ground:
                self.step = "Recovery"
        elif self.step == "Defending":
            defending(self)
        elif self.step == "Dodge":
            self.dodge.step(self.FPS)
            self.controls = self.dodge.controls
            self.controls.boost = 0
            if self.dodge.finished and self.info.my_car.on_ground:
                self.step = "Catching"
        elif self.step == "Recovery":
            self.recovery.step(self.FPS)
            self.controls = self.recovery.controls
            if self.info.my_car.on_ground:
                self.step = "Catching"
        elif self.step == "Shooting":
            shooting(self)

    def render_string(self, string):
        self.renderer.begin_rendering('The State')
        if self.step == "Dodge1":
            self.renderer.draw_line_3d(self.info.my_car.pos, self.dodge.target,
                                       self.renderer.black())
        self.renderer.draw_line_3d(self.info.my_car.pos, self.bounces[0][0],
                                   self.renderer.blue())
        self.renderer.draw_string_2d(
            20, 20, 3, 3, string + " " + str(abs(self.info.ball.vel[2])) +
            " " + str(sign(self.team) * self.info.ball.vel[1]),
            self.renderer.red())
        self.renderer.end_rendering()

    def should_defending(self):
        ball = self.info.ball
        car = self.info.my_car
        our_goal = self.info.my_goal.center
        car_to_ball = ball.pos - car.pos
        in_front_of_ball = distance_2d(ball.pos, our_goal) < distance_2d(
            car.pos, our_goal)
        backline_intersect = line_backline_intersect(
            self.info.my_goal.center[1], vec2(car.pos), vec2(car_to_ball))
        return in_front_of_ball and abs(backline_intersect) < 2000