Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 4
0
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
Esempio n. 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
Esempio n. 6
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)
Esempio n. 7
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
Esempio n. 8
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