예제 #1
0
    def step(self, dt):
        car = self.car
        target = ground(self.target)

        car_speed = norm(car.velocity)
        time_left = (ground_distance(car, target) -
                     self.finish_distance) / max(car_speed + 500, 1400)
        forward_speed = dot(car.forward(), car.velocity)

        if self.driving and car.on_ground:
            self.action.target_pos = target
            self._time_on_ground += dt

            # check if it's a good idea to dodge, wavedash or halfflip
            if (self._time_on_ground > 0.2 and car.position[2] < 200
                    and angle_to(car, target, forward_speed < 0) < 0.1):
                # if going forward, use a dodge or a wavedash
                if forward_speed > 0:
                    use_boost_instead = self.waste_boost and car.boost > 20

                    if car_speed > 1200 and not use_boost_instead:
                        if time_left > self.DODGE_DURATION:
                            dodge = Dodge(car)
                            dodge.duration = 0.05
                            dodge.direction = vec2(direction(car, target))
                            self.action = dodge
                            self.driving = False

                        elif time_left > self.WAVEDASH_DURATION:
                            wavedash = Wavedash(car)
                            wavedash.direction = vec2(direction(car, target))
                            self.action = wavedash
                            self.driving = False

                # if going backwards, use a halfflip
                elif time_left > self.HALFFLIP_DURATION and car_speed > 800:
                    self.action = HalfFlip(car, self.waste_boost
                                           and time_left > 3)
                    self.driving = False

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

        # make sure we're not boosting airborne
        if self.driving and not car.on_ground:
            self.controls.boost = False

        # make sure we're not stuck turtling
        if not car.on_ground:
            self.controls.throttle = 1

        if self.action.finished and not self.driving:
            self.driving = True
            self._time_on_ground = 0
            self.action = self.drive
            self.drive.backwards = False

        if ground_distance(car,
                           target) < self.finish_distance and self.driving:
            self.finished = True
예제 #2
0
    def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        self.game.read_game_information(packet, self.get_rigid_body_tick(),
                                        self.get_field_info())
        self.controls = SimpleControllerState()

        next_state = self.state

        if self.state == State.RESET:

            self.timer = 0.0

            # put the car in the middle of the field
            car_state = CarState(physics=Physics(location=Vector3(0, 0, 18),
                                                 velocity=Vector3(0, 0, 0),
                                                 rotation=Rotator(0, 0, 0),
                                                 angular_velocity=Vector3(
                                                     0, 0, 0)),
                                 jumped=False,
                                 double_jumped=False)

            theta = random.uniform(0, 6.28)
            pos = Vector3(sin(theta) * 1000.0, cos(theta) * 1000.0, 100.0)

            # put the ball somewhere out of the way
            ball_state = BallState(
                physics=Physics(location=pos,
                                velocity=Vector3(0, 0, 0),
                                rotation=Rotator(0, 0, 0),
                                angular_velocity=Vector3(0, 0, 0)))

            self.set_game_state(
                GameState(ball=ball_state, cars={self.game.id: car_state}))

            next_state = State.WAIT

        if self.state == State.WAIT:

            if self.timer > 0.2:
                next_state = State.INITIALIZE

        if self.state == State.INITIALIZE:

            self.action = Wavedash(self.game.my_car)
            self.action.direction = vec2(self.game.ball.location)

            next_state = State.RUNNING

        if self.state == State.RUNNING:

            self.action.step(self.game.time_delta)
            self.controls = self.action.controls

            if self.timer > self.timeout:
                next_state = State.RESET

        self.timer += self.game.time_delta
        self.state = next_state

        return self.controls
예제 #3
0
파일: States.py 프로젝트: meckern/RLBotPack
class WaveDashing(baseState):
    def __init__(self, agent, targVec):
        baseState.__init__(self, agent)
        self.action = Wavedash(agent.game.my_car)
        self.action.direction = vec2(targVec[0], targVec[1])

    def update(self):
        self.action.step(self.agent.deltaTime)
        if self.action.finished:
            self.active = False
        return self.action.controls
예제 #4
0
파일: travel.py 프로젝트: robbai/RLBotPack
    def step(self, dt):
        car = self.car
        target = ground(self.target)

        car_vel = norm(car.velocity)
        time_left = (distance(car, target) - self.finish_distance) / max(car_vel + 500, 1400)
        vf = dot(car.forward(), car.velocity)

        if self.driving and car.on_ground:
            self.action.target_pos = target
            self._time_on_ground += dt
            
            if self._time_on_ground > 0.2 and car.position[2] < 200 and angle_to(car, target, vf < 0) < 0.1:

                if vf > 0:
                    if car_vel > 1000 and (not self.waste_boost or car.boost < 10):
                        if time_left > self.dodge_duration:
                            dodge = Dodge(car)
                            dodge.duration = 0.05
                            dodge.direction = vec2(direction(car, target))
                            self.action = dodge
                            self.driving = False

                        elif time_left > self.wavedash_duration:
                            wavedash = Wavedash(car)
                            wavedash.direction = vec2(direction(car, target))
                            self.action = wavedash
                            self.driving = False

                elif time_left > self.halflip_duration and car_vel > 800:
                    self.action = HalfFlip(car, self.waste_boost and time_left > 3)
                    self.driving = False
                    

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

        if self.driving and not car.on_ground:
            self.controls.boost = False

        if self.action.finished and not self.driving:
            self.driving = True
            self._time_on_ground = 0
            self.action = self.drive
            self.drive.backwards = False

        if distance(car, target) < self.finish_distance and self.driving:
            self.finished = True

        if not self.waste_boost and car.boost < 70:
            self.controls.boost = 0
예제 #5
0
파일: States.py 프로젝트: meckern/RLBotPack
 def __init__(self, agent, targVec):
     baseState.__init__(self, agent)
     self.action = Wavedash(agent.game.my_car)
     self.action.direction = vec2(targVec[0], targVec[1])