import random

ruggednesses = ['flat', 'hilly', 'mountainous']
humidities = ['rocky', 'dry', 'humid', 'wet', 'oceanic']
life_size = ['none', 'micro', 'mega']
temps = ['molten', 'hot', 'warm', 'temperate', 'cool', 'cold', 'frozen']


def get_planet(index):
    ruggedness = random.choice(ruggednesses)
    humidity = random.choice(humidities)
    temp = get_temperature(index, humidity)

    if temp not in ['frozen', 'molten'] or random.random() > 0.75:
        flora = random.choice(life_size)
        fauna = random.choice(life_size) if flora != 'none' else 'none'
    else:
        flora = 'none'
        fauna = 'none'
    return {
        'index': index,
        'ruggedness': ruggedness,
        'humidity': humidity,
        'temperature': temp,
        'flora': flora,
        'fauna': fauna
    }


def get_temperature(index, humidity):
    # humid worlds are more likely to be temperate

    temp_dice = humidities.index(humidity) + 1
    temp_rolls = [random.randrange(0, len(temps)) for _ in range(temp_dice)]
    sum_temp_rolls = sum(temp_rolls) + index - 3
    temp_index = sum_temp_rolls // len(temp_rolls)
    temp_index = clamp(temp_index, 0, len(temps) - 1)
    return temps[temp_index]


def clamp(n, lower, upper):
    return max(lower, min(upper, n))


if __name__ == '__main__':
    for i in range(15):
        print(get_planet(i))
