Example #1
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)))
         },
     )
    def test_process(self, game_tick_packet: GameTickPacket):

        self.car_physics = Physics(velocity=Vector3(0, 0, 10))
        self.ball_state = BallState(physics=Physics(
            velocity=Vector3(0, 0, 10), location=Vector3(0, 0, 800)))

        chrono = self.info.time - self.initialization_time
        if chrono > self.timeout or self.mechanic.finished and chrono > 0.04:

            log_message = "Finished" if self.mechanic.finished else "Timed out"
            log_message = log_message + ". Took " + str(chrono) + " Seconds."
            self.logger.info(self.mechanic.__class__.__name__ + ": " +
                             log_message)

            self.initialize_agent()

        self.set_game_state(
            GameState(cars={self.index: CarState(physics=self.car_physics)},
                      ball=self.ball_state))
Example #3
0
    def reset(self, training_name=None):
        """ Resets the training without changing any of the random values. """
        if (not training_name):
            training_name = self.training_name

        car_state = CarState(physics=Physics(velocity=self.car_vel,
                                             rotation=self.car_rot,
                                             location=self.car_loc),
                             boost_amount=self.car_boost)

        ball_state = BallState(
            Physics(velocity=self.ball_vel,
                    location=self.ball_loc,
                    angular_velocity=self.ball_av))

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

        self.car.set_game_state(self.game_state)
Example #4
0
    def set_gamestate_straight_moving(self):
        # put the car in the middle of the field
        car_state = CarState(
            physics=Physics(location=Vector3(0, -1000, 18),
                            velocity=Vector3(0, 0, 0),
                            rotation=Rotator(0, math.pi / 2, 0),
                            angular_velocity=Vector3(0, 0, 0)))

        # put the ball in the middle of the field

        ball_state = BallState(
            physics=Physics(location=Vector3(0, 1500, 93),
                            velocity=Vector3(0, random.randint(-250, 800),
                                             random.randint(700, 800)),
                            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}))
Example #5
0
    def get_output(self, packet: GameTickPacket):
        current_time = packet.game_info.seconds_elapsed % (
            self.delay + self.recording[-1][0])

        # State-set and wait.
        if current_time < self.delay:
            if current_time < self.delay / 10:
                car_state = CarState(
                    boost_amount=100,
                    physics=Physics(
                        location=Vector3(0, -4500, 18),
                        velocity=Vector3(0, 0, -100),
                        rotation=Rotator(0, math.pi / 2, 0),
                        angular_velocity=Vector3(0, 0, 0),
                    ),
                )
                ball_state = BallState(
                    Physics(
                        location=Vector3(0, 4500, 92.75),
                        velocity=Vector3(0, 0, 0),
                        angular_velocity=Vector3(0, 0, 0),
                    ))
                game_state = GameState(ball=ball_state,
                                       cars={self.index: car_state})
                self.set_game_state(game_state)
            return self.convert_output_to_v4([0] * 8)

        current_time -= self.delay

        # Render.
        self.renderer.begin_rendering()
        self.renderer.draw_string_2d(
            20,
            20,
            4,
            4,
            str(round(current_time, 3)),
            self.renderer.white(),
        )
        self.renderer.end_rendering()

        # Controls.
        return self.find_controls(current_time)
Example #6
0
 def reset(self):
     """Resets game data after each genome"""
     ball_state = BallState(
         Physics(velocity=Vector3(0, 0, 0),
                 location=Vector3(self.pos, 5000, 3000),
                 angular_velocity=Vector3(0, 0, 0)))
     car_state = CarState(jumped=False,
                          double_jumped=False,
                          boost_amount=33,
                          physics=Physics(velocity=Vector3(0, 0, 0),
                                          rotation=Rotator(45, 90, 0),
                                          location=Vector3(0.0, -4608, 500),
                                          angular_velocity=Vector3(0, 0,
                                                                   0)))
     game_info_state = GameInfoState(game_speed=1)
     game_state = GameState(ball=ball_state,
                            cars={self.index: car_state},
                            game_info=game_info_state)
     self.set_game_state(game_state)
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(physics=Physics(location=Vector3(0, 0, 92.75),
                                        velocity=Vector3(0, 0, 0),
                                        angular_velocity=Vector3(0, 0, 0))),
         cars={
             0:
             CarState(physics=Physics(location=Vector3(
                 self.car_start_x, 3000, 0),
                                      rotation=Rotator(0, pi / 2, 0),
                                      velocity=Vector3(0, 0, 0),
                                      angular_velocity=Vector3(0, 0, 0)),
                      jumped=False,
                      double_jumped=False,
                      boost_amount=0)
         },
         boosts={i: BoostState(0)
                 for i in range(34)},
     )
Example #8
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(physics=Physics(
             location=Vector3(2000, 1000, 100),
             velocity=Vector3(2000, rng.uniform(-500, 500), 0),
             angular_velocity=Vector3(0, 0, 0))),
         cars={
             0: CarState(
                 physics=Physics(
                     location=Vector3(1000, -1000, 100),
                     rotation=Rotator(0, 0, 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 #9
0
    def set_state_stationary(self):
        # put the car in the middle of the field
        car_state = CarState(physics=Physics(
            location=Vector3(0, -2500, 18),
            velocity=Vector3(0, 0, 0),
            rotation=Rotator(0, math.pi / 2, 0),
            angular_velocity=Vector3(0, 0, 0),
        ),
                             boost_amount=100)

        # put the ball in the middle of the field
        ball_state = BallState(physics=Physics(
            location=Vector3(0, 0, ball_z),
            velocity=Vector3(0, 0, 0),
            angular_velocity=Vector3(0, 0, 0),
        ))

        self.set_game_state(
            GameState(ball=ball_state, cars={self.game.id: car_state}))
Example #10
0
    def set_gamestate_straight_moving_towards(self):
        # put the car in the middle of the field
        car_state = CarState(physics=Physics(
            location=Vector3(0, 0, 18),
            velocity=Vector3(0, 0, 0),
            angular_velocity=Vector3(0, 0, 0),
        ))

        # put the ball in the middle of the field

        ball_state = BallState(physics=Physics(
            location=Vector3(0, 2500, 93),
            velocity=Vector3(0, -250, 700),
            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}))
Example #11
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(physics=Physics(
             location=Vector3(self.ball_start_x + rng.uniform(-30, 30), self.ball_start_y, self.ball_start_z),
             velocity=Vector3(0, 0, 0),
             angular_velocity=Vector3(0, 0, 0))),
         cars={
             0: CarState(
                 physics=Physics(
                     location=Vector3(self.car_start_x, self.car_start_y, 0),
                     rotation=Rotator(0, self.car_angle, 0),
                     velocity=Vector3(0, 0, 0),
                     angular_velocity=Vector3(0, 0, 0)),
                 jumped=False,
                 double_jumped=False,
                 boost_amount=100)
         },
         boosts={1: BoostState(100)},
     )
Example #12
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     car_pos = Vector3(2000, 500, 25)
     ball_pos = Vector3(2000, 1000, 100)
     ball_state = BallState(
         Physics(location=ball_pos, velocity=Vector3(0, 1000, 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 #13
0
 def reset(self):
     #RESET TRAINING ATTRIBUTES AFTER EACH GENOME
     ball_state = BallState(
         Physics(velocity=Vector3(0, 0, 0),
                 location=Vector3(self.pos, 5000, 3000),
                 angular_velocity=Vector3(0, 0, 0)))
     car_state = CarState(jumped=False,
                          double_jumped=False,
                          boost_amount=33,
                          physics=Physics(velocity=Vector3(0, 0, 0),
                                          rotation=Rotator(45, 90, 0),
                                          location=Vector3(0.0, -4608, 500),
                                          angular_velocity=Vector3(0, 0,
                                                                   0)))
     game_info_state = GameInfoState(game_speed=1)
     game_state = GameState(ball=ball_state,
                            cars={self.index: car_state},
                            game_info=game_info_state)
     self.set_game_state(game_state)
Example #14
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(ball=BallState(physics=Physics(
         location=as_cls(Vector3,
                         parse_item(rng, self.ball.get("location", V0))),
         velocity=as_cls(Vector3,
                         parse_item(rng, self.ball.get("velocity", V0))),
         angular_velocity=as_cls(
             Vector3, parse_item(rng, self.ball.get("angular_velocity",
                                                    V0))),
         rotation=as_cls(Rotator,
                         parse_item(rng, self.ball.get("rotation", R0))),
     )),
                      cars={
                          i: CarState(physics=Physics(
                              location=as_cls(
                                  Vector3,
                                  parse_item(rng, car.get("location", V0))),
                              velocity=as_cls(
                                  Vector3,
                                  parse_item(rng, car.get("velocity", V0))),
                              angular_velocity=as_cls(
                                  Vector3,
                                  parse_item(
                                      rng, car.get("angular_velocity",
                                                   V0))),
                              rotation=as_cls(
                                  Rotator,
                                  parse_item(rng, car.get("rotation", R0))),
                          ),
                                      jumped=parse_item(
                                          rng, car.get("jumped", False)),
                                      double_jumped=parse_item(
                                          rng,
                                          car.get("double_jumped", False)),
                                      boost_amount=parse_item(
                                          rng, car.get("boost_amount", 0)))
                          for i, car in enumerate(self.cars)
                      },
                      boosts={
                          i: BoostState(parse_item(rng, v))
                          for i, v in enumerate(self.boosts)
                      })
Example #15
0
    def setCarState(self):
        game_state = GameState()
        self.set_game_state(game_state)
        car_state = CarState(jumped=False,
                             double_jumped=False,
                             boost_amount=100,
                             physics=Physics(location=Vector3(x=-1800,
                                                              y=0,
                                                              z=550),
                                             velocity=Vector3(x=0, y=0, z=0),
                                             rotation=Rotator(
                                                 math.pi / 2, 0, 0),
                                             angular_velocity=Vector3(0, 0,
                                                                      0)))

        ball_state = BallState(
            Physics(location=Vector3(1000, 0, 800),
                    velocity=Vector3(x=0, y=0, z=0)))
        game_state = GameState(ball=ball_state, cars={self.index: car_state})
        self.set_game_state(game_state)
Example #16
0
    def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
        car_state = CarState(
            boost_amount=100,
            physics=Physics(
                location=Vector3(-2000+500*rng.n11(), -4250, 20),
                velocity=Vector3(1400, 0, 0),
                rotation=Rotator(0, 0, 0),
                angular_velocity=Vector3(0, 0, 0)
                )
            )

        ball_state = BallState(
            Physics(
                location=Vector3(-1700, -4000, 100),
                velocity=Vector3(1500+500*rng.n11(), 150+50*rng.n11(), 0)
                )
            )

        game_state = GameState(ball=ball_state, cars={0: car_state})
        return game_state
Example #17
0
    def initialize_agent(self):

        if not hasattr(self, 'car_physics'):
            self.car_physics = Physics()

        self.car_physics.rotation = Rotator(
            random.uniform(-math.pi / 2, math.pi / 2),
            random.uniform(-math.pi, math.pi),
            random.uniform(-math.pi, math.pi))
        self.car_physics.location = Vector3(random.uniform(-1000, 1000),
                                            random.uniform(-1000, 1000),
                                            random.uniform(50, 1400))
        self.car_physics.angular_velocity = Vector3(random.uniform(-5, 5),
                                                    random.uniform(-5, 5),
                                                    random.uniform(-5, 5))

        self.ball_state = BallState(physics=Physics(
            velocity=Vector3(0, 0, 20), location=Vector3(0, 0, 800)))

        self.initialization_time = self.info.time
Example #18
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(physics=Physics(
             location=Vector3(self.ball_x, self.ball_y, self.ball_z),
             velocity=Vector3(self.ball_vx, self.ball_vy, self.ball_vz),
             angular_velocity=Vector3(self.ball_sx, self.ball_sy,
                                      self.ball_sz))),
         cars={
             0:
             CarState(physics=Physics(
                 location=Vector3(self.car_x, self.car_y, self.car_z),
                 rotation=Rotator(self.car_pitch, self.car_spin,
                                  self.car_roll),
                 velocity=Vector3(0, 0, 0),
                 angular_velocity=Vector3(0, 0, 0)),
                      boost_amount=100)
         },
         boosts={i: BoostState(0)
                 for i in range(34)},  # Is this needed.
     )
    def checkState(self):
        if self.state.expired:
            self.state.reset(
            )  #If our state has expired, reset it and choose the next available state

            car = CarState(boost_amount=100,
                           physics=Physics(velocity=vector3(0, 0, 0),
                                           angular_velocity=vector3(0, 0, 0),
                                           location=vector3(400, 3000, 20),
                                           rotation=Rotator(0, math.pi / 2,
                                                            0)))
            ball = BallState(physics=Physics(location=vector3(-3000, 1000, 94),
                                             velocity=vector3(1500, 0, 0)))
            game = GameState(ball=ball, cars={self.index: car})
            self.set_game_state(game)
            flag = True
            for item in self.states:
                if item.available() == True:
                    self.state = item
                    flag = False
            if flag:  #If no states are available do this:
                self.state = wait()
Example #20
0
 def reset(self):
     ball_start = Vec3(
         x=random.randint(-1365, 1365),
         y=random.randint(-1280, -1200),
         z=random.randint(50, 100),
     )
     ball_end = Vec3(
         x=random.randint(-800, 800),
         y=random.randint(-5125, -5120),
         z=random.randint(50, 100),
     )
     ball_speed = (ball_end-ball_start).normalized() * random.randint(1600, 1800)
     car_start = Vec3(
         x=random.randint(-440, 440),
         y=random.randint(-5560, -5120),
         z=50,
     )
     car_rot = Rotator(
         pitch=0,
         yaw=math.pi/2 + (random.random()-0.5)*math.pi/6,
         roll=0,
     )
     self.set_game_state(GameState(
         ball=BallState(physics=Physics(
             location=ball_start.to_vector3(),
             velocity=ball_speed.to_vector3(),
         )),
         cars={0: CarState(physics=Physics(
             location=car_start.to_vector3(),
             rotation=car_rot,
             velocity=Vector3(0, 0, 0),
             angular_velocity=Vector3(0, 0, 0)
         ), 
             boost_amount=random.randint(60, 90),
         )},
         game_info=GameInfoState(
             game_speed=self.speed
         )
     ))
Example #21
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     car_spawn_area: utils.Area = utils.RectPrism(Vector3(0, 0, 17), 8000, 8000, 0)
     ball_spawn_area: utils.Area = utils.RectPrism(Vector3(0, 0, 1000), 8000, 8000, 400)
     ball_velocity_area: utils.Area = utils.Sphere(Vector3(0, 0, 0), 600)
     ball_loc: Vector3 = ball_spawn_area.random_point_inside(rng)
     car_loc: Vector3 = car_spawn_area.random_point_inside(rng)
     return GameState(
         ball=BallState(physics=Physics(
             location=ball_loc,
             velocity=ball_velocity_area.random_point_inside(rng),
             angular_velocity=Vector3(0, 0, 0))),
         cars={
             0: CarState(
                 physics=Physics(
                     location=car_loc,
                     rotation=utils.rotator_from_dir(sub(ball_loc, car_loc)),
                     velocity=Vector3(0, 0, 0),
                     angular_velocity=Vector3(0, 0, 0)),
                 boost_amount=100),
         },
         boosts={i: BoostState(0) for i in range(34)},
     )
Example #22
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(Physics(
             location=Vector3(0, 5000, 100),
             velocity=Vector3(0, 2000, 500)
         )),
         cars={
             0: CarState(boost_amount=95, physics=Physics(
                 location=Vector3(200, -5400, 100),
                 rotation=Rotator(0, 3, 0),
                 velocity=Vector3(0, 0, 0),
                 angular_velocity=Vector3(0, 0, 0),
             )),
             1: CarState(boost_amount=95, physics=Physics(
                 location=Vector3(-200, -5400, 100),
                 rotation=Rotator(0, 3, 0),
                 velocity=Vector3(0, 0, 0),
                 angular_velocity=Vector3(0, 0, 0),
             )),
         },
         # game_info=GameInfoState(game_speed=0.1),
     )
Example #23
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(physics=Physics(location=Vector3(0, 0, 100),
                                        velocity=Vector3(0, 0, 0),
                                        angular_velocity=Vector3(0, 0, 0))),
         cars={
             0:
             CarState(physics=Physics(location=Vector3(
                 self.car_start_x, self.car_start_y, 16.5),
                                      rotation=Rotator(0, self.car_yaw, 0),
                                      velocity=Vector3(0, 0, 0),
                                      angular_velocity=Vector3(0, 0, 0)),
                      boost_amount=33),
             1:
             CarState(physics=Physics(location=Vector3(
                 -self.car_start_x, -self.car_start_y, 16.5),
                                      rotation=Rotator(0, -self.car_yaw, 0),
                                      velocity=Vector3(0, 0, 0),
                                      angular_velocity=Vector3(0, 0, 0)),
                      boost_amount=33)
         },
     )
Example #24
0
    def reset_gamestate(self):
        print('> reset_gamestate()')

        # Initialize inputs
        self.reset_for_ground_shots()
        t = self.target
        b = Ball(self.game.ball)
        c = Car(self.game.cars[self.index])
        b.location = to_vec3(self.initial_ball_location)
        b.velocity = to_vec3(self.initial_ball_velocity)
        c.location = to_vec3(self.initial_car_location)
        c.velocity = to_vec3(self.initial_car_velocity)

        # Point car at ball
        c.rotation = look_at(
            vec3(b.location[0] - c.location[0], b.location[1] - c.location[1],
                 0), vec3(0, 0, 1))
        rotator = rotation_to_euler(c.rotation)

        # Reset
        self.aerial = None
        self.dodge = None
        self.rotation_input = None
        self.timer = 0.0

        # Set gamestate
        car_state = CarState(boost_amount=100,
                             physics=Physics(
                                 location=self.initial_car_location,
                                 velocity=self.initial_car_velocity,
                                 rotation=rotator,
                                 angular_velocity=Vector3(0, 0, 0)))
        ball_state = BallState(
            Physics(location=self.initial_ball_location,
                    velocity=self.initial_ball_velocity,
                    rotation=Rotator(0, 0, 0),
                    angular_velocity=Vector3(0, 0, 0)))
        game_state = GameState(ball=ball_state, cars={self.index: car_state})
        self.set_game_state(game_state)
Example #25
0
    def setup(self, packet, drones, start_time) -> StepResult:
        self.game_interface.set_game_state(
            GameState(game_info=GameInfoState(game_speed=0.25)))

        car_states = {}
        radian_spacing = 2 * math.pi / 60

        for index, drone in enumerate(drones):
            if 61 <= index <= 64:
                car_states[drone.index] = CarState(
                    Physics(location=Vector3(3520, 5100, 0),
                            velocity=Vector3(0, 0, 0)))
                continue

            if index == 60:
                car_states[drone.index] = CarState(
                    Physics(location=Vector3(0, 0, 20),
                            velocity=Vector3(0, 0, 0),
                            rotation=Rotator(0, 0, 0)))
                continue

            progress = index * radian_spacing
            target = Vec3(radius * math.sin(progress),
                          radius * math.cos(progress), 0)

            car_states[drone.index] = CarState(
                Physics(location=Vector3(target.x, target.y, 20),
                        velocity=Vector3(0, 0, 0),
                        rotation=Rotator(0, -progress, 0)))

        self.game_interface.set_game_state(
            GameState(cars=car_states,
                      ball=BallState(
                          physics=Physics(location=Vector3(0, 0, 155),
                                          velocity=Vector3(0, 0, 0),
                                          angular_velocity=Vector3(0, 0, 0)))))

        return StepResult(finished=True)
Example #26
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     self.grader.graders[1].max_duration_seconds = 5
     return GameState(
         game_info=GameInfoState(game_speed=1),
         ball=BallState(
             physics=Physics(location=Vector3(rng.uniform(-500, 500),
                                              rng.uniform(-500, 500), 94),
                             velocity=Vector3(0, rng.uniform(-300, 500),
                                              rng.uniform(0, 600)),
                             angular_velocity=Vector3(0, 0, 0))),
         cars={
             0:
             CarState(physics=Physics(location=Vector3(
                 rng.uniform(-100, -90), -2200, 25),
                                      rotation=Rotator(0, pi / 2, 0),
                                      velocity=Vector3(0, 1000, 0),
                                      angular_velocity=Vector3(0, 0, 0)),
                      boost_amount=80),
             1:
             CarState(physics=Physics(
                 location=Vector3(10000, 10000, 10000)))
         },
     )
Example #27
0
    def reset_game(self):
        car_state = CarState(
            Physics(
                location=Vector3(0,-1000, 20),
                velocity=Vector3(0, 0,0),
                rotation=Rotator(0, 0.5 * np.pi, 0),
                angular_velocity=Vector3(0, 0, 0)),
            jumped=False,
            double_jumped=False,
            boost_amount=100
        )
        ball_state = BallState(
            Physics(
                location=Vector3(0, 0, 20),
                velocity=Vector3(0, 0,0),
                rotation=Rotator(0, 0.5 * np.pi, 0),
                angular_velocity=Vector3(0, 0, 0)
            )
        )

        game_state = GameState(cars={0: car_state}, ball=ball_state)
        # game_state = GameState()
        self.game_interface.set_game_state(game_state)
Example #28
0
    def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
        minboost = self.boost if self.minboost is None else self.minboost
        maxboost = self.boost if self.maxboost is None else self.maxboost

        return GameState(
            ball=BallState(physics=Physics(
                location=Vector3(self.ball_x, self.ball_y, self.ball_z),
                velocity=Vector3(self.ball_vx, self.ball_vy, self.ball_vz),
                angular_velocity=Vector3(self.ball_sx, self.ball_sy,
                                         self.ball_sz))),
            cars={
                0:
                CarState(physics=Physics(location=Vector3(
                    self.car_x, self.car_y, self.car_z),
                                         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=rng.uniform(minboost, maxboost))
            },
            boosts={i: BoostState(0)
                    for i in range(34)},  # Is this needed.
        )
Example #29
0
    def set_state(self):
        number = int(self.time) % 20
        enemy_state = CarState(physics=Physics(location=Vector3(
            x=0, y=self.enemy_goal_loc[1], z=100),
                                               rotation=Rotator(0, 0, 0)))

        car_state = CarState(boost_amount=100,
                             physics=Physics(location=Vector3(x=-1500,
                                                              y=-4000,
                                                              z=20),
                                             rotation=Rotator(
                                                 0, math.pi / 2, 0),
                                             velocity=Vector3(x=0, y=1000,
                                                              z=0)))
        ball_state = BallState(
            Physics(location=Vector3(-2000, -3000, 700),
                    velocity=Vector3(x=00, y=500, z=200)))
        game_info_state = GameInfoState(game_speed=0.3)
        game_state = GameState(ball=ball_state,
                               cars={self.index: car_state},
                               game_info=game_info_state)
        # game_state = GameState(cars={self.index: car_state})
        #if keyboardd.is_pressed('t'):
        self.set_game_state(game_state)
    def reset_state(self):
        # If car is moving backwards, set it on the front goal, and vice versa
        if self.throttle_list[self.throttle_index] <= 0:
            speed_multiplier = 1
        else:
            speed_multiplier = -1

        car_state = CarState(
            boost_amount=100,
            physics=Physics(
                velocity=Vector3(0, 10000 * speed_multiplier, 0),
                location=Vector3(x=0, y=0),
                rotation=Rotator(0, math.pi / 2, 0),
                angular_velocity=Vector3(0, 0, 0),
            ),
        )
        # Setting the run start time
        self.reset_time = 0

        ball_state = BallState(Physics(location=Vector3(z=3000)))

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

        self.set_game_state(game_state)