import tracery

system = {
    "origin": [
        "Center:\n* #star##planets_switch##feature_switch##inhabitants_switch#",
    ],
    "star": [
        "#color# sun",
        "#color# #color# sun",
        "twin #color# suns",
    ],
    "color": [
        "red",
        "orange",
        "yellow",
        "green",
        "blue",
        "purple",
        "white",
        "gold",
        "silver",
        "copper"
    ],
    "planets_switch": [
        "",
        "\nPlanets\n#planets#",
        "\nPlanets\n#planets#",
        "\nPlanets\n#planets#",
        "\nPlanets\n#planets#",
        "\nPlanets\n#planets#",
        "\nPlanets\n#planets#"
    ],
    "feature_switch": [
        "",
        "\nFeature\n* #feature#"
    ],
    "inhabitants_switch": [
        "",
        "",
        "",
        "\nInhabitants\n* #inhabitants#"
    ],
}

planets = {    
    "planets": [
        "* #hot_planets:planet#",
        "* #temperate_planets:planet#",
        "* #cold_planets:planet#",
        "* #hot_planets:planet#\n* #temperate_planets:planet#",
        "* #temperate_planets:planet#\n* #cold_planets:planet#",
        "* #hot_planets:planet#\n* #cold_planets:planet#",
        "* #hot_planets:planet#\n* #temperate_planets:planet#\n* #cold_planets:planet#",
    ],
    "hot_planets:planet": [
        "scalding planet",
        "molten planet",
        "acid planet",
        "hot desert planet",
        "hot rocky planet",
        "fire world",
        "volcanic planet",
    ],
    "temperate_planets:planet": [
        "temperate gas giant",
        "#temperate_planets:biome# world",
        "#temperate_planets:biome# world (#features:temperate#)",
        "#special_planets:biome# world",
        "twin #temperate_planets:biome# worlds"
    ],
    "features:temperate": [
        "large moon",
        "high gravity",
        "bleak",
        "irradiated",
        "poor minerals",
        "tidal locked",
        "unstable tectonics",
        "weak magical field",
        "asteroid impacts",
        "atmospheric hallucinogen",
        "hazardous weather",
        "hostile fauna",
        "high gravity",
        "low gravity",
        "wild storms",
        "asteroid belt",
        "high quality minerals",
        "extensive moon system",
        "lush",
        "natural beauty",
        "strong magical field",
        "titanic flora",
        "titanic fauna",
        "subterranean civilization",
        "abandoned subterranean cities",
        "dead god",
        "precursor ruins",
        "crystal spires",
        "primitives",
        "city world"
    ],
    "features:hot": [
        "large moon",
        "active volcanos",
        "magma seas",
        "magma geysers",
        "high gravity",
        "irradiated",
        "poor minerals",
        "tidal locked",
        "unstable tectonics",
        "weak magical field",
        "asteroid impacts",
        "hazardous weather",
        "hostile fauna",
        "high gravity",
        "low gravity",
        "wild storms",
        "asteroid belt",
        "high quality minerals",
        "strong magical field",
        "titanic flora",
        "titanic fauna",
        "subterranean civilization",
        "abandoned subterranean cities",
        "precursor ruins",
        "crystal spires"
    ],
    "hot_planets:planet_and_feature": [
        "#hot_planets:planet#",
        "#hot_planets:planet# (#features:hot#)"
    ],
    "temperate_planets": [
        "#temperate_planets:planet#"
    ],
    "features:cold": [
        "large moon",
        "high gravity",
        "bleak",
        "irradiated",
        "poor minerals",
        "weak magical field",
        "asteroid impacts",
        "hazardous weather",
        "hostile fauna",
        "high gravity",
        "low gravity",
        "wild storms",
        "asteroid belt",
        "high quality minerals",
        "extensive moon system",
        "strong magical field",
        "titanic flora",
        "titanic fauna",
        "subterranean civilization",
        "abandoned subterranean cities",
        "dead god",
        "precursor ruins",
        "crystal spires",
        "ice spires"
    ],
    "hot_planets": [
        "#hot_planets:planet_and_feature#"
    ],
    "cold_planets": [
        "#cold_planets:planet_and_feature#"
    ],
    "temperate_planets:biome": [
        "jungle",
        "swamp",
        "taiga",
        "tundra",
        "plains",
        "continental",
        "ocean",
        "desert",
        "forest",
        "volcanic",
        "dead",
        "tomb",
        "barren",
        "acid",
        "crystal",
        "cloud",
        "crystal"
    ],
    "special_planets:biome": [
        "clockwork",
        "biological",
    ],
    "cold_planets:planet": [
        "ice planet",
        "icy rock",
        "freezing gas giant",
        "cold gas giant"
    ],
    "planet-system": [
        "Center:\n* #star#\nPlanets:\n#planets#"
    ],
    "cold_planets:planet_and_feature": [
        "#cold_planets:planet#",
        "#cold_planets:planet# (#features:cold#)"
    ],
}

features = {
    "feature": [
        "a habitat",
        "the wreckage of a space battle",
    ]
}

inhabitants = {
    "inhabitants": [
        "#uncivilized#, #presence#",
        "#uncivilized#, #presence#",
        "#uncivilized#, #presence#",
        "#faction#, #civil_presence#",
        "#faction#, #civil_presence#",
        "#faction#, #civil_presence#",
        "#a_single_large_thing#, #status#"
    ],
    "uncivilized": [
        "drift denizens",
        "sentient crystals",
        "space fauna"
    ],
    "a_single_large_thing": [
        "an elder god",
        "an otherworldly horror",
        "a world eater",
        "a living planet"
    ],
    "status": [
        "sleeping",
        "dead",
        "being born",
        "enraged",
        "beckoning"
    ],
    "presence": [
        "heavy presence",
        "medium presence",
        "light presence",
        "grave",
        "nests"
    ],
    "faction": [
        "#political_faction#",
        "#political_faction#",
        "#political_faction#",
        "#political_faction#",
        "rebel #political_faction#",
        "scum",
        "alien menace",
        "otherworldly entities",
        "The Tek",
        "free people"
    ],
    "political_faction": [
        "feudalists",
        "imperialists",
        "capitalists",
        "militarists",
        "pacifists",
        "authoritarians",
        "egalitarians",
        "materialists"
        "spiritualists"
        "rebels",
        "xenophobes",
        "xenophiles",
        "spacers"
    ],
    "civil_presence": [
        "starbase",
        "heavy presence",
        "medium presence",
        "light presence",
        "outpost",
        "colonists",
        "farmers",
        "civilians",
        "scouts",
        "mining drones",
        "extremists",
        "trading post",
        "scientists",
        "explorers",
        "refugees",
        "holy site"
    ]
}

rules = dict()
rules.update(system)
rules.update(planets)
rules.update(features)
rules.update(inhabitants)

def get_planet():
    grammar = tracery.Grammar(rules)
    return grammar.flatten("#origin#")


if __name__ == '__main__':
    print(get_planet())
