Exemplo n.º 1
0
    def __init__(self, name=None, orbit_distance=None, min_size=0.0,
                 max_size=0.0):
        """
        This is the constructor for the `Planet` class. Since `Planet` is an
        abstract class, this constructor should never be called unless called
        by one of `Planet`'s three subclasses.

        Keyword Args:
            name (str):
                The name of the planet we're creating.

            orbit_distance (float):

            min_size (float);

            max_size (float):
        """

        # Preconditions.
        assert min_size != 0.0
        assert max_size != 0.0
        assert min_size < max_size

        # Assign name.
        if name is not None:
            self.name = name
        else:
            self.name = ""

        # Assign size.
        self.size = rand_float_range(min_size, max_size)

        # If we are given an orbit distance, then calculate an orbital period
        if orbit_distance is not None:
            self.orbit_distance = orbit_distance
            self.orbit_period = orbit_distance * rand_float_range(0.5, 1.5)
        else:
            self.orbit_distance = -1
            self.orbit_period = -1
Exemplo n.º 2
0
    def __init__(self, name, star_spectral_class=None, generate_planets=False):
        """
        Args:
            name (str):
                The name of this system.

        Postconditions:
            If a `star_spectral_class` was given, then a `star_size` will also
            be calculated.
        """

        self.name = name
        
        if star_spectral_class is not None:
            self.star_spectral_class = star_spectral_class
            # TODO set size
            self.star_size = rand_float_range(0.5, 3.0)
Exemplo n.º 3
0
def generate_system(name, scheme):
    """
    Args:
        name (str):
            What we want to name this `System`.

        scheme (int):
            A system naming scheme code defined at the top of this module. Use
            `SYSTEM_SCHEME_SYLLABLES` to generate new names for planets. Use
            `SYSTEM_SCHEME_STAR` to name planets after `name` (for example,
            "Ceti Alpha V" and "Ceti Alpha VI").

    Returns:
        A `System` generated at random.

    Notes:
        The `position` attribute of the returned `System` will not be set.
    """

    # Declare global variables.
    global SYSTEM_MAX_PLANETS
    global SYSTEM_MIN_PLANETS

    # How many planets does this system have?
    num_planets = random.randint(SYSTEM_MIN_PLANETS, SYSTEM_MAX_PLANETS)

    # Generate a random spectral class.
    star_spectral_class = _random_spectral_class()

    # Now calculate the maximum and minimum distances planets can be between.
    min_orbit_dist = 0.1
    max_orbit_dist = 30.0 # TODO

    # Calculate the orbiting distances between the planets.
    orbit_distances = []
    for a in xrange(0, num_planets):
        distance = rand_float_range(min_orbit_dist, max_orbit_dist)
        orbit_distances.append(distance)
    orbit_distances.sort()

    # This is the probability of a planet being rocky as a function of its
    # orbital distance from its star.
    chance_rocky = lambda d: 0.5 # TODO

    # This is the probability of a planet being habitable GIVEN that it is
    # rocky as a function of its orbital distance.
    chance_habitable = lambda d: 0.25 # TODO

    # Begin creating the planets
    planets = []
    a = 1 # used for iteration
    for distance in orbit_distances:
        planet_type = None

        # Case: Rocky or habitable planet
        if coinflip(chance_rocky(distance)):
            planet_type = planet_lib.RockyPlanet
            if coinflip(chance_habitable(distance)):
                planet_type = planet_lib.HabitablePlanet
        else:
            planet_type = planet_lib.GasPlanet

        planet = planet_type(orbit_distance=distance)

        # TODO setup planet
        planet.name = _planet_name(name, scheme, a)
        planets.append(planet)
        a += 1

    # Setup the system that we will return
    system = System(name, star_spectral_class=star_spectral_class)
    return system