Example #1
0
 def process_choice(self, choice: BotAction):
     player_index = self.get_player_index_by_name(choice.data[PLAYER_NAME])
     if player_index is not None:
         car = self.game_tick_packet.game_cars[player_index]
         if choice.action_type == FLIP_CAR:
             flipped = get_flipped_orientation(car.physics.rotation)
             self.set_game_state(
                 GameState(cars={player_index: CarState(physics=Physics(rotation=flipped.to_rotator()))}))
         if choice.action_type == NUDGE_CAR:
             car_vel = Vec3(car.physics.velocity)
             rand_vec = Vec3(random() - .5, random() - .5, 0).normalized()
             nudge_vel = Vector3(car_vel.x + rand_vec.x * 700, car_vel.y + rand_vec.y * 700, car_vel.z + 500)
             self.set_game_state(
                 GameState(cars={player_index: CarState(physics=Physics(velocity=nudge_vel))}))
    def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:

        num_players = self.match_config.num_players
        assert num_players == len(
            self.spawns
        ), 'Number of players does not match the number of spawns.'

        car_states = {}
        for index, player in enumerate(self.match_config.player_configs):
            assert (player.team == 0) == (index < len(self.blue_spawns)), \
            f"Blue/Orange players in match_config don't match the Blue/Orange spawns: Expected {len(self.blue_spawns)} blue player_configs, followed by {len(self.orange_spawns)} orange ones."

            car_states[index] = CarState(
                boost_amount=33,
                physics=Physics(location=self.spawns[index].pos,
                                velocity=Vector3(0, 0, 0),
                                rotation=self.spawns[index].rot,
                                angular_velocity=Vector3(0, 0, 0)))

        ball_state = BallState(
            Physics(location=Vector3(0, 0, 93),
                    velocity=Vector3(0, 0, 0),
                    rotation=Rotator(0, 0, 0),
                    angular_velocity=Vector3(0, 0, 0)))

        game_state = GameState(ball=ball_state, cars=car_states)
        return game_state
Example #3
0
    def game_state_reset(self):
        crot = Rotator(random.uniform(-np.pi, np.pi),
                       random.uniform(-np.pi, np.pi),
                       random.uniform(-np.pi, np.pi))

        car_state = CarState(physics=Physics(location=Vector3(0, 0, 1000),
                                             velocity=Vector3(0, 0, 0),
                                             rotation=None,
                                             angular_velocity=Vector3(0, 0,
                                                                      0)),
                             boost_amount=100)

        vel = random.choice([(-1, 0), (1, 0), (0, -1), (0, 1)])

        bloc = Vector3(1000 * vel[0] + 200 * vel[1],
                       1000 * vel[1] + 200 * vel[0], random.choice([500,
                                                                    1300]))

        bvel = Vector3(-12 * vel[0] + 3 * vel[1], -12 * vel[1] + 3 * vel[0], 0)

        ball_state = BallState(
            physics=Physics(location=bloc,
                            velocity=bvel,
                            rotation=Rotator(0, 0, 0),
                            angular_velocity=Vector3(0, 0, 0)))

        self.state = GameState(ball=ball_state, cars={self.index: car_state})
        return self.state
Example #4
0
    def setup_kickoff(self, packet):

        kickoff_pos_mapping = [
            # Normal, new as dist
            (Vec3(2048, -2560), 3000),  # Left corner
            (Vec3(-2048, -2560), 3500),  # Right corner
            (Vec3(256.0, -3840), 4000),  # Back left
            (Vec3(-256.0, -3840), 4500),  # Back right
            (Vec3(0, -4608), 5000),  # Far back
        ]

        car_states = {}
        for index in range(packet.num_cars):
            car = packet.game_cars[index]
            tsign = 1 if car.team == 0 else -1
            for (kickoff_pos, dist) in kickoff_pos_mapping:
                car_pos = tsign * Vec3(car.physics.location.x,
                                       car.physics.location.y)
                if (car_pos - kickoff_pos).shorter_than(20):
                    new_pos = Vec3(0, -tsign * dist, 25)
                    break

            yaw = tsign * math.pi / 2.0

            car_state = CarState(
                Physics(location=new_pos.desired(), rotation=Rotator(yaw=yaw)))
            car_states[index] = car_state
        return car_states
Example #5
0
    def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
        enemy_goal_center: Vector3 = Vector3(0, 5120 * self.team, 93)
        car_spawn_block: utils.Area = utils.RectPrism(Vector3(0, 0, 17), 8000,
                                                      8000, 0)
        car_loc: Vector3 = car_spawn_block.random_point_inside(rng)
        car_facing: Rotator = utils.rotator_from_dir(
            sub(enemy_goal_center, car_loc))
        relative: Vector3 = sub(enemy_goal_center, car_loc)
        #Spawn the ball halfway between us and the enemy goal
        ball_loc: Vector3 = add(
            car_loc, Vector3(relative.x / 2, relative.y / 2, relative.z / 2))
        ball_loc.z = 93

        return GameState(
            ball=BallState(physics=Physics(location=ball_loc,
                                           velocity=Vector3(0, 0, 0),
                                           angular_velocity=Vector3(0, 0, 0))),
            cars={
                0:
                CarState(physics=Physics(location=car_loc,
                                         rotation=car_facing,
                                         velocity=Vector3(0, 0, 0),
                                         angular_velocity=Vector3(0, 0, 0)),
                         boost_amount=33),
            },
            boosts={i: BoostState(0)
                    for i in range(34)},
        )
Example #6
0
    def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
        num_players = self.match_config.num_players
        assert num_players == len(
            self.spawns
        ), 'Number of players does not match the number of spawns.'

        car_states = {}
        for index in range(num_players):
            car_states[index] = CarState(
                boost_amount=33,
                physics=Physics(location=self.spawns[index].pos,
                                velocity=Vector3(0, 0, 0),
                                rotation=self.spawns[index].rot,
                                angular_velocity=Vector3(0, 0, 0)))

        ball_state = BallState(
            Physics(location=Vector3(0, 0, 93),
                    velocity=Vector3(0, 0, 0),
                    rotation=Rotator(0, 0, 0),
                    angular_velocity=Vector3(0, 0, 0)))

        # game_state = GameState(ball=ball_state, cars=car_states, console_commands=['Set WorldInfo TimeDilation 0.5'])
        game_state = GameState(
            ball=ball_state,
            cars=car_states,
            console_commands=['Set WorldInfo TimeDilation 1'],
            boosts={i: BoostState(0)
                    for i in range(34)})
        return game_state
Example #7
0
    def execute(self):

        car_state = CarState(jumped=False,
                             double_jumped=False,
                             boost_amount=87,
                             physics=Physics(location=rlv3(-1000, -2000, 20),
                                             velocity=rlv3(0, 0, 0),
                                             rotation=rlv3(0, -1, 0),
                                             angular_velocity=rlv3(0, 0, 0)))

        ball_state = BallState(
            Physics(location=rlv3(1000, 1100, 100),
                    velocity=rlv3(0, 0, 0),
                    rotation=rlv3(0, 0, 0),
                    angular_velocity=rlv3(0, 0, 0)))

        game_state = GameState(ball=ball_state,
                               cars={self.agent.index: car_state})

        self.agent.set_game_state(game_state)
        self.expired = True

        r = 1000
        x = [r / 2, -r, -r, r, r, -r / 2]
        y = [-r / 2, -r, r, r, -r, -r / 2]
        nodes = np.asfortranarray([x, y])
        curve = structs.test(nodes, bezier.Curve.from_nodes(nodes))

        self.agent.renderer.draw_polyline_3d(curve.get_path_points(),
                                             self.agent.renderer.blue())

        self.substate = substates.pick_state(
            self, self.agent, self.car, self.ball.location, 2300,
            self.hierarchy)  # Drive(self.car, target, 2000)
        return self.substate.step(1.0 / 60.0)
Example #8
0
def boost_and_turn_test(agent):
    agent.state = boost_and_turn()
    test_time = time.time() - agent.test_start
    if(test_time > 6):
        car_state = CarState(
            jumped=False, 
            double_jumped=False, 
            boost_amount=87, 
            physics=Physics(location=Vector3(x=-1000,y=2000,z=0),
                            velocity=Vector3(x=0, y=0, z=0), 
                            rotation=Rotator(np.pi, np.pi / 2, np.pi), 
                            angular_velocity=Vector3(x=0, y=0, z=0)))
        
        ball_state = BallState(
            physics=Physics(location=Vector3(x=0,y=4000,z=0),
                            velocity=Vector3(x=0, y=0, z=0), 
                            rotation=Rotator(np.pi / 2, 0, 0), 
                            angular_velocity=Vector3(x=0, y=0, z=0)))

        game_state = GameState(ball=ball_state, cars={agent.index: car_state})

        agent.set_game_state(game_state)
        agent.test_start = time.time()
    else:
        return
Example #9
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(physics=Physics(
             # location=Vector3(self.ball_x + rng.uniform(-10, 10), self.ball_y + rng.uniform(-10, 10), self.ball_z),
             location=Vector3(self.ball_x +
                              rng.uniform(-500, 500), self.ball_y +
                              rng.uniform(-500, 500), self.ball_z),
             velocity=Vector3(self.ball_vx +
                              rng.uniform(-500, 500), self.ball_vy +
                              rng.uniform(-500, 500), self.ball_vz),
             angular_velocity=Vector3(0, 0, 0))),
         cars={
             0:
             CarState(
                 physics=Physics(
                     # location=Vector3(self.car_start_x + rng.uniform(-1500, 1500), self.car_start_y, 0),
                     location=Vector3(self.car_x, self.car_y, 17),
                     rotation=Rotator(0, self.car_spin, 0),
                     velocity=Vector3(0, 0, 0),
                     angular_velocity=Vector3(0, 0, 0)),
                 jumped=False,
                 double_jumped=False,
                 boost_amount=100)
         },
         boosts={i: BoostState(0)
                 for i in range(34)},  # Is this needed.
     )
Example #10
0
def aerialATBA_test(agent):
    agent.state = aerialATBA()
    test_time = time.time() - agent.test_start
    if(test_time > 20):
        car_state = CarState(
            jumped=False, 
            double_jumped=False, 
            boost_amount=87, 
            physics=Physics(location=Vector3(x=0,y=3000,z=0),
                            velocity=Vector3(x=0, y=0, z=0), 
                            rotation=Rotator(np.pi, np.pi / 2, np.pi), 
                            angular_velocity=Vector3(x=0, y=0, z=0)))
        ball_state = BallState(
            physics=Physics(location=Vector3(x=0,y=0,z=500),
                            velocity=Vector3(x=0, y=0, z=0), 
                            rotation=Rotator(np.pi / 2, 0, 0), 
                            angular_velocity=Vector3(x=0, y=0, z=0)))

        game_state = GameState(ball=ball_state, cars={agent.index: car_state})

        agent.set_game_state(game_state)
        agent.test_start = time.time()
    # else:
    #     ball_state = BallState(
    #         physics=Physics(location=Vector3(x=0,y=0,z=500),
    #                         velocity=Vector3(x=0, y=0, z=0), 
    #                         rotation=Rotator(np.pi / 2, 0, 0), 
    #                         angular_velocity=Vector3(x=0, y=0, z=0)))
    #     game_state = GameState(ball=ball_state)
    #     agent.set_game_state(game_state)
        

        
        return
Example #11
0
    def reset_shot(self):
        zero_vector = Vector3(x=0, y=0, z=0)

        ball_start_location = Vector3(x=0, y=0, z=800)

        car_start_location = Vector3(x=0, y=0, z=600)
        car_start_rotation = Rotator(
            # pitch=math.pi / 2,
            pitch=math.pi / 2 + random.random() * 0.1 * math.pi,
            yaw=random.random() * 2 * math.pi,
            roll=random.random() * 2 * math.pi)

        game_state = GameState(
            ball=BallState(
                Physics(location=ball_start_location,
                        velocity=zero_vector,
                        angular_velocity=zero_vector)),
            cars={
                self.index:
                CarState(physics=Physics(location=car_start_location,
                                         rotation=car_start_rotation,
                                         velocity=zero_vector,
                                         angular_velocity=zero_vector))
            })
        self.set_game_state(game_state)
        self.has_started_episode = False
        self.has_reset = True
Example #12
0
    def exec(self, bot) -> SimpleControllerState:

        if bot.info.time > 10 and bot.info.time > self.next_test:
            self.next_test = bot.info.time + DURATION

            dir = Vec3(random.random() - 0.5,
                       random.random() - 0.5,
                       random.random() - 0.5)
            self.ball_pos = CAR_POS + normalize(dir) * BALL_OFFSET

        bot.set_game_state(
            GameState(
                ball=BallState(
                    Physics(location=self.ball_pos.to_desired_vec(),
                            velocity=ANTI_GRAV.to_desired_vec())),
                cars={
                    bot.index:
                    CarState(
                        physics=Physics(location=CAR_POS.to_desired_vec(),
                                        velocity=ANTI_GRAV.to_desired_vec()))
                }))

        target_rot = looking_in_dir(self.ball_pos - CAR_POS)

        return bot.fly.align(bot, target_rot)
Example #13
0
 def setup(self, rng: random.Random) -> GameState:
     self._reset_state()
     return GameState(
         ball=BallState(physics=Physics(
             location=self.ball_location,
             velocity=Vector3(0, 0, 0),
             angular_velocity=Vector3(0, 0, 0))),
         cars={
             0: CarState(
                 physics=Physics(
                     location=self.car_location,
                     rotation=Vector3(
                         0,
                         math.atan2(  # face the ball
                             self.ball_location.y - self.car_location.y,
                             self.ball_location.x - self.car_location.x,
                         ),
                         0
                     ),
                     velocity=Vector3(0, 0, 0),
                     angular_velocity=Vector3(0, 0, 0)),
                 jumped=False,
                 double_jumped=False,
                 boost_amount=100)
         },
         boosts={i: BoostState(0) for i in range(34)},
     )
Example #14
0
    def initialize_agent(self):
        m = -1 if self.team else 1
        f = -1 if self.flip else 1

        if self.diagonal:
            car_physics = Physics(
                velocity=Vector3(0, 0, 0),
                rotation=Rotator(0, (45 + m * 90) / 180 * math.pi, 0),
                angular_velocity=Vector3(0, 0, 0),
                location=Vector3(f * m * 2048, m * -2560, 17.148628))

        ball_physics = Physics(location=Vector3(0, 0, 92.739998),
                               velocity=Vector3(0, 0, 0),
                               angular_velocity=Vector3(0, 0, 0))

        car_state = CarState(jumped=False,
                             double_jumped=False,
                             boost_amount=34,
                             physics=car_physics)

        ball_state = BallState(physics=ball_physics)

        game_state = GameState(ball=ball_state, cars={self.index: car_state})

        self.set_game_state(game_state)

        self.initialization_time = self.info.time
        self.action.reset_status()
Example #15
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
Example #16
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()

        if not self.action:
            self.action = Reorient(self.my_car)
            self.action.eps_phi = 0.01
            self.action.eps_omega = 0.02

        if self.timer == 0.0:

            # randomly generate a proper orthogonal matrix
            self.action.target_orientation = axis_to_rotation(
                vec3(random.uniform(-2, 2), random.uniform(-2, 2),
                     random.uniform(-2, 2)))

        o = self.action.target_orientation
        f = vec3(o[0, 0], o[1, 0], o[2, 0])
        position = Vector3(0, 0, 1000)
        velocity = Vector3(0, 0, 0)

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

        # spawn the ball in front of the desired orientation to visually indicate where we're trying to go
        ball_state = BallState(
            physics=Physics(location=Vector3(500 * f[0], 500 *
                                             f[1], 500 * f[2] + 1000),
                            velocity=Vector3(0, 0, 0),
                            angular_velocity=Vector3(0, 0, 0)))

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

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

        self.timer += self.game.time_delta
        if self.timer > 2.0:
            self.timer = 0.0

        error = angle_between(self.my_car.orientation,
                              self.action.target_orientation)

        self.renderer.begin_rendering("path")
        red = self.renderer.create_color(255, 230, 30, 30)
        self.renderer.draw_string_2d(50, 50, 3, 3,
                                     f"error: {error:.4f} radians", red)
        self.renderer.draw_string_2d(50, 100, 3, 3,
                                     f"Roll:   {self.controls.roll:+.2f}", red)
        self.renderer.draw_string_2d(50, 150, 3, 3,
                                     f"Pitch: {self.controls.pitch:+.2f}", red)
        self.renderer.draw_string_2d(50, 200, 3, 3,
                                     f"Yaw:  {self.controls.yaw:+.2f}", red)
        self.renderer.end_rendering()

        return self.controls
Example #17
0
    def __hide(self, packet_car):
        print("There I go!")
        self.__car_sim.reset(SimPhysics.p(packet_car.physics))
        p = Physics(location=Vector3(3520, 5100, 0), velocity=Vector3(0, 0, 0))
        self.set_game_state(GameState(cars={self.index: CarState(physics=p)}))

        self.__hidden = True
        self.__teleporting = 0
Example #18
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(physics=Physics(location=Vector3(0, 0, 18),
                                        velocity=Vector3(0, 0, 0),
                                        angular_velocity=Vector3(0, 0, 0))),
         cars={
             0:
             CarState(physics=Physics(location=Vector3(0, 2500, 93),
                                      velocity=Vector3(0, -250, 700),
                                      rotation=Rotator(0, 0, 0),
                                      angular_velocity=Vector3(0, 0, 0)),
                      boost_amount=87),
             1:
             CarState(physics=Physics(
                 location=Vector3(10000, 10000, 10000)))
         },
     )
Example #19
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     car_pos = Vector3(0, -2500, 25)
     ball_pos = Vector3(1000 * rng.n11(), rng.uniform(0, 1500), 100)
     ball_state = BallState(
         Physics(location=ball_pos, velocity=Vector3(0, 550, 0)))
     car_state = CarState(boost_amount=87,
                          jumped=True,
                          double_jumped=True,
                          physics=Physics(
                              location=car_pos,
                              rotation=Rotator(0, pi / 2, 0),
                              velocity=Vector3(0, 0, 0),
                              angular_velocity=Vector3(0, 0, 0),
                          ))
     enemy_car = CarState(physics=Physics(location=Vector3(0, 5120, 25)))
     game_state = GameState(ball=ball_state, cars={0: car_state})
     return game_state
Example #20
0
 def game_state_update(self, packet):
     ball_state = BallState(
         physics=Physics(location=Vector3(0, 0, 1500),
                         velocity=Vector3(0, 0, 0),
                         rotation=Rotator(0, 0, 0),
                         angular_velocity=Vector3(0, 0, 0)))
     car_state = CarState(boost_amount=100)
     return GameState(ball=ball_state, cars={self.index: car_state})
Example #21
0
    def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        self.info.read_packet(packet)
        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, 20),
                                velocity=Vector3(0, 0, 0),
                                rotation=Rotator(0, 0, 0),
                                angular_velocity=Vector3(0, 0, 0)))

            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.index: 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:

            # in this demonstration, we choose to dodge toward the ball
            c = self.info.my_car
            target = self.info.ball.pos
            self.action = AirDodge(c, 0.1, target)

            next_state = State.RUNNING

        if self.state == State.RUNNING:

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

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

        self.timer += 0.01666
        self.state = next_state

        return self.controls
Example #22
0
 def setup_newround(self, packet):
     car_states = {}
     yaw, yaw_mir = self.yaw_randomizor()
     for p in range(packet.num_cars):
         car = packet.game_cars[p]
         if car.team == 0:
             car_state = CarState(boost_amount=100,
                                  physics=Physics(
                                      location=Vector3(0, -1000, 17),
                                      rotation=Rotator(yaw=yaw,
                                                       pitch=0,
                                                       roll=0),
                                      velocity=Vector3(0, 0, 0),
                                      angular_velocity=Vector3(0, 0, 0)))
             car_states[p] = car_state
         elif car.team == 1:
             car_state = CarState(boost_amount=100,
                                  physics=Physics(
                                      location=Vector3(0, 1000, 17),
                                      rotation=Rotator(yaw=yaw_mir,
                                                       pitch=0,
                                                       roll=0),
                                      velocity=Vector3(0, 0, 0),
                                      angular_velocity=Vector3(0, 0, 0)))
             car_states[p] = car_state
     if self.horz_ball_var == 'Off':
         ball_vel_x = ball_vel_y = 0
     elif self.horz_ball_var == 'On':
         ball_vel_x = (np.random.random() * 2 - 1) * 500
         ball_vel_y = (np.random.random() * 2 - 1) * 300
     if self.vert_ball_var == 'Off':
         ball_vel_z = -1
         ball_pos_z = 93
     elif self.vert_ball_var == 'On':
         ball_vel_z = np.random.random() * 360 - 460
         ball_pos_z = np.random.random() * 200 + 500
     self.paused_car_states = car_states
     ball_state = BallState(
         Physics(location=Vector3(0, 0, ball_pos_z),
                 velocity=Vector3(ball_vel_x, ball_vel_y, ball_vel_z)))
     self.game_state = GameState(ball=ball_state, cars=car_states)
     self.set_game_state(self.game_state)
     self.prev_time = self.cur_time
     self.game_phase = -1
 def process_choice(self, choice: BotAction):
     boost_amount = 0
     if choice.action_type == GIVE_FULL_BOOST:
         # People can't see that they have full boost on the client side, and will be unable to either boost or pick up pads if it's on 100!
         boost_amount = 98
     player_index = self.get_player_index_by_name(choice.data[PLAYER_NAME])
     if player_index is not None:
         self.set_game_state(
             GameState(
                 cars={player_index: CarState(boost_amount=boost_amount)}))
Example #24
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     car_pos = Vector3(3500 * rng.n11(), rng.uniform(0, -4000), 25)
     ball_pos = Vector3(car_pos.x, car_pos.y + 500, 500)
     return GameState(
         ball=BallState(physics=Physics(location=ball_pos,
                                        velocity=Vector3(0, 0, 500),
                                        angular_velocity=Vector3(0, 0, 0))),
         cars={
             0:
             CarState(physics=Physics(location=car_pos,
                                      rotation=Rotator(0, pi / 2, 0),
                                      velocity=Vector3(0, 0, 0),
                                      angular_velocity=Vector3(0, 0, 0)),
                      boost_amount=87),
             1:
             CarState(physics=Physics(
                 location=Vector3(10000, 10000, 10000)))
         },
     )
Example #25
0
 def __init__(self):
     #define all different car states here
     self.carStateBasic = CarState(boost_amount=100,
                                   physics=Physics(
                                       location=Vector3(0, 0, 17.01),
                                       velocity=Vector3(0, 0, 0),
                                       rotation=Rotator(pitch=0,
                                                        yaw=0,
                                                        roll=0),
                                       angular_velocity=Vector3(0, 0, 0)))
Example #26
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     car_pos = Vector3(0, 2500, 25)
     ball_pos = Vector3(0, 2000, 100)
     ball_state = BallState(
         Physics(location=ball_pos, velocity=Vector3(0, -1300, 0)))
     car_state = CarState(boost_amount=0,
                          jumped=True,
                          double_jumped=True,
                          physics=Physics(location=car_pos,
                                          velocity=Vector3(0, -1000, 0),
                                          rotation=Rotator(0, -pi / 2, 0)))
     enemy_car = CarState(physics=Physics(
         location=Vector3(10000, 10000, 10000)))
     game_state = GameState(ball=ball_state,
                            cars={
                                0: car_state,
                                1: enemy_car
                            })
     return game_state
Example #27
0
    def reset_gstate(self):
        car_state = CarState(Physics(location=Vector3(0, 4000, 1500),
                                     rotation=Rotator(0, -1, 0),
                                     velocity=Vector3(0, 0, 0)),
                             boost_amount=100)
        ball_state = BallState(
            Physics(location=Vector3(0, 0, 1500), velocity=Vector3(0, 0, 0)))

        game_state = GameState(ball=ball_state, cars={self.index: car_state})

        self.set_game_state(game_state)
Example #28
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
Example #29
0
    def reset(self):
        game_state = GameState()
        self.set_game_state(game_state)
        car_state = CarState(
            physics(location=Vector3(x=-1000, y=0, z=250),
                    velocity=Vector3(x=0, y=0, z=0),
                    rotation=Rotator(0, 0, 0),
                    angular_velocity=Vector3(0, 0, 0)))

        ball_state = BallState(Physics(location=Vector3(500, 0, None)))
        game_state = GameState(ball=ball_state, cars={self.index: car_state})
        self.set_game_state(game_state)
Example #30
0
    def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        self.info.read_packet(packet)
        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, 20),
                                velocity=Vector3(1000, 0, 0),
                                rotation=Rotator(0, 0, 0),
                                angular_velocity=Vector3(0, 0, 0)))

            # put the ball somewhere out of the way
            ball_state = BallState(
                physics=Physics(location=Vector3(0, -3000, 100),
                                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.index: 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 = HalfFlip(self.info.my_car)

            next_state = State.RUNNING

        if self.state == State.RUNNING:

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

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

        self.timer += 0.01666
        self.state = next_state

        return self.controls