def test_next_planet_type(self): from gravita import planet types = set() for i in range(100): type = planet.next_planet_type() self.assertTrue(type) self.assert_(type in planet.planet_types, type) types.add(type) self.assertEqual(types, set(planet.planet_types))
def add_planet(self, planet_type=None, location=None): """Add a planet to the map. The planet type and location can be specified, if not they will be randomly chosen. """ if planet_type is not None: assert planet_type in planet.planet_types, \ "Invalid planet type %s" % planet_type if location is None: assert self._available_sectors, "Cannot add planet, map is full" location = random.choice(list(self._available_sectors)) x, y = location for dx in (-1, 0, 1): for dy in (-1, 0, 1): self._available_sectors.discard((x + dx, y + dy)) p = self[location].planet = planet.Planet( name=self.generate_planet_name(), type=planet_type or planet.next_planet_type(), location=location, size=random.random() * 0.7 + 0.3) return p