def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
        car_pos = Vector3(5600, 0, 0)
        ball_pos = Vector3(rng.randrange(-800, 800),
                           rng.randrange(-5000, 5000), 93)
        ball_vel = Vector3(rng.randrange(-2000, 2000),
                           rng.randrange(-2000, 2000), 0)
        ball_ang_vel = Vector3(0, 0, 0)

        ball_state = BallState(
            Physics(location=ball_pos,
                    velocity=ball_vel,
                    angular_velocity=ball_ang_vel))
        car_state = CarState(boost_amount=100,
                             jumped=False,
                             double_jumped=False,
                             physics=Physics(location=car_pos,
                                             rotation=Rotator(0, 0, 0),
                                             velocity=Vector3(0, 0, 0),
                                             angular_velocity=Vector3(0, 0,
                                                                      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
Beispiel #2
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.
     )
Beispiel #3
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     vel_mul = rng.uniform(1.5, 2.0)
     return GameState(
         ball=BallState(physics=Physics(
             location=Vector3(0, -1500, 100),
             velocity=Vector3(vel_mul * 350 * rng.uniform(-1, 1), vel_mul * -2000, 0),
             angular_velocity=Vector3(0, 0, 0))),
         cars={
             # Striker
             0: CarState(
                 physics=Physics(
                     location=Vector3(0, 0, 15),
                     rotation=Rotator(0, -pi / 2, 0),
                     velocity=Vector3(0, 0, 0),
                     angular_velocity=Vector3(0, 0, 0)),
                 jumped=False,
                 double_jumped=False,
                 boost_amount=100),
             # Goalie
             1: CarState(
                 physics=Physics(
                     location=Vector3(0, -5000, 15),
                     rotation=Rotator(0, rng.uniform(-.1, .1), 0),
                     velocity=Vector3(0, 0, 0),
                     angular_velocity=Vector3(0, 0, 0)),
                 jumped=True,
                 double_jumped=True,
                 boost_amount=100),
         },
         boosts={i: BoostState(0) for i in range(34)},
     )
 def random_point_inside(self, rng: SeededRandomNumberGenerator) -> Vector3:
     # Not gaurenteed to be even distrobution because volume is approximate
     area: Area = rng.choices(self.areas, self.probs)[0]
     point: Vector3 = area.random_point_inside(rng)
     while not self.is_in(point):
         area = rng.choices(self.areas, self.probs)[0]
         point = area.random_point_inside(rng)
     return point
    def random_point_inside(self, rng: SeededRandomNumberGenerator) -> Vector3:
        phi: float = rng.random() * math.pi * 2
        theta: float = rng.random() * math.pi
        radius: float = rng.random() * self.radius

        offset: Vector3 = Vector3(r * math.sin(theta) * math.cos(phi),
                                  r * math.sin(theta) * math.sin(phi),
                                  r * math.cos(theta))
        return add(self.center, offset)
Beispiel #6
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(ball=BallState(
         Physics(location=Vector3(rng.uniform(900, 1300),
                                  rng.uniform(0, 1500), 100),
                 velocity=Vector3(0, 550, 0))),
                      cars={
                          0:
                          CarState(boost_amount=87,
                                   jumped=True,
                                   double_jumped=True,
                                   physics=Physics(
                                       location=Vector3(2000, -2500, 25),
                                       rotation=Rotator(0, pi / 2, 0),
                                       velocity=Vector3(0, 0, 0),
                                       angular_velocity=Vector3(0, 0, 0),
                                   ))
                      })
Beispiel #7
0
    def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
        random_position = Vector3(rng.uniform(-3000, 3000),
                                  rng.uniform(-4000, 4000), 18)
        random_velocity = Vector3(rng.uniform(-1000, 1000),
                                  rng.uniform(-1000, 1000), 0)
        random_rotation = Rotator(0, rng.uniform(-math.pi, math.pi), 0)

        car_physics = Physics(location=random_position,
                              velocity=random_velocity,
                              rotation=random_rotation,
                              angular_velocity=Vector3(0, 0, 0))

        boost = rng.uniform(0, 50)

        car_state = CarState(boost_amount=boost, physics=car_physics)

        return GameState(cars={0: car_state})
 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
Beispiel #9
0
 def test_statement(statement, result):
     rng = SeededRandomNumberGenerator(Random(10))
     res = parse_statement(rng, statement)
     if isinstance(res, Vector3):
         assert (res.x == result.x and res.y == result.y
                 and res.z == result.z)
     else:
         assert res == result, f"'{statement}' Failed: {res} != {result}"
Beispiel #10
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     self.grader.graders[1].max_duration_seconds = 2
     return GameState(
         game_info=GameInfoState(game_speed=1),
         ball=BallState(physics=Physics(
             location=Vector3(rng.uniform(-100, 100), -500, 800),
             velocity=Vector3(rng.uniform(-100, 100), -1500, 900),  # 
             angular_velocity=Vector3(0, 0, 0))),
         cars={
             0:
             CarState(physics=Physics(location=Vector3(
                 rng.uniform(-300, 300), -3000, 17),
                                      rotation=Rotator(0, pi * -0.5, 0),
                                      velocity=Vector3(0, -1500, 0),
                                      angular_velocity=Vector3(0, 0, 0)),
                      boost_amount=60)
         },
     )
Beispiel #11
0
    def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
        rng = random
        car_physics = Physics()
        car_physics.rotation = Rotator(math.sinh(rng.uniform(-1, 1)),
                                       rng.uniform(-math.pi, math.pi),
                                       rng.uniform(-math.pi, math.pi))
        car_physics.location = Vector3(0, 0, 800)

        velocity = (rng.normalvariate(0, 1) for _ in range(3))
        norm = sum(x**2 for x in velocity)**0.5
        car_physics.angular_velocity = Vector3(*(x / norm * 5.5
                                                 for x in velocity))

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

        return GameState(cars={0: CarState(physics=car_physics)},
                         ball=ball_state)
Beispiel #12
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(physics=Physics(
             # location=Vector3(1000 * rng.n11(), rng.uniform(0, 1500), 100),
             location=Vector3(rng.uniform(-1000, 1000),
                              rng.uniform(-1000, 1000), 100),
             velocity=Vector3(rng.uniform(-1000, 1000),
                              rng.uniform(-1000, 1000), 1000),
             angular_velocity=Vector3(0, 0, 0))),
         cars={
             0:
             CarState(physics=Physics(location=Vector3(0, -2500, 18),
                                      rotation=Rotator(0, pi / 2, 0),
                                      velocity=Vector3(0, 0, 0),
                                      angular_velocity=Vector3(0, 0, 0)),
                      boost_amount=87),
         },
     )
Beispiel #13
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(physics=Physics(
             location=Vector3(0, 2500, 100),
             velocity=Vector3(0, 0, rng.uniform(0, 1500)),
             angular_velocity=Vector3(0, 0, 0))),
         cars={
             0: CarState(
                 physics=Physics(
                     location=Vector3(rng.uniform(3000, 4000), rng.uniform(2000, 3000), 100),
                     rotation=Rotator(0, rng.uniform(0, pi), 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)},
     )
Beispiel #14
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)))
         },
     )
Beispiel #15
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
Beispiel #16
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)))
         },
     )
    def test_exercises_before_grading(self):
        for file in _common_exercises_dir.glob('**/*.py'):
            if file.name == 'ball_prediction.py':
                # Something is making the "python stopped working" dialog show up
                # even though it passes. Probably not cleaning something up properly.
                continue

            module = load_external_module(file)
            if not hasattr(module, 'make_default_playlist'):
                continue
            playlist = module.make_default_playlist()
            for ex in playlist:
                rng = SeededRandomNumberGenerator(Random(14))
                self.assertIsInstance(ex.match_config, MatchConfig)
                self.assertIsInstance(ex.grader, Grader)
                self.assertIsInstance(ex.make_game_state(rng), GameState)
Beispiel #18
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(physics=Physics(location=Vector3(0, 4400, 100),
                                        velocity=Vector3(0, 0, 0),
                                        angular_velocity=Vector3(0, 0, 0))),
         cars={
             0:
             CarState(physics=Physics(location=Vector3(
                 900 * rng.n11(), 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)
         },
     )
Beispiel #19
0
    def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
        m = 1
        f = rng.choice([-1, 1])

        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)

        return GameState(ball=ball_state, cars={0: car_state})
Beispiel #20
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)},
     )
Beispiel #21
0
 def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
     return GameState(
         ball=BallState(physics=Physics(
             location=Vector3(rng.uniform(-800, 800), 0, 0),
             velocity=Vector3(0, 0, 0),
             angular_velocity=Vector3(0, 0, 0))),
         cars={
             0: CarState(
                 physics=Physics(
                     # location=Vector3(rng.uniform(-800, 800), -5800, 0),
                     location=Vector3(0, -5800, 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)}, # Is this needed.
     )
Beispiel #22
0
    def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState:
        car_physics = Physics()
        car_physics.rotation = Rotator(rng.uniform(-math.pi / 2, math.pi / 2),
                                       rng.uniform(-math.pi, math.pi),
                                       rng.uniform(-math.pi, math.pi))
        car_physics.location = Vector3(rng.uniform(-1000, 1000),
                                       rng.uniform(-1000, 1000),
                                       rng.uniform(50, 1400))
        car_physics.angular_velocity = Vector3(rng.uniform(-5, 5),
                                               rng.uniform(-5, 5),
                                               rng.uniform(-5, 5))

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

        return GameState(cars={0: CarState(physics=car_physics)},
                         ball=ball_state)
    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.
        )
Beispiel #24
0
 def setup(self, rng: Random) -> GameState:
     return self.exercise.make_game_state(SeededRandomNumberGenerator(rng))
def get_car_start_near_goal(rng: SeededRandomNumberGenerator) -> Vector3:
    return Vector3(rng.uniform(1000, 2000), 3000, 0)
 def random_point_inside(self, rng: SeededRandomNumberGenerator) -> Vector3:
     offset: Vector3 = Vector3(self.width / 2 * rng.n11(),
                               self.depth / 2 * rng.n11(),
                               self.height / 2 * rng.n11())
     return add(self.center, offset)
 def random_point_inside(self, rng: SeededRandomNumberGenerator) -> Vector3:
     offset: Vector3 = Vector3(
         math.cos(rng.random() * math.pi * 2) * self.radius,
         math.sin(rng.random() * math.pi * 2) * self.radius,
         rng.n11() * height)
     return add(self.center, offset)