commit 94c3c2a44f26d2a324fe4c616795824f058f903e Author: gauvainboiche Date: Thu Dec 5 15:56:08 2024 +0100 First commit diff --git a/__pycache__/pl_stat.cpython-312.pyc b/__pycache__/pl_stat.cpython-312.pyc new file mode 100644 index 0000000..5ec8aba Binary files /dev/null and b/__pycache__/pl_stat.cpython-312.pyc differ diff --git a/pl_stat.py b/pl_stat.py new file mode 100644 index 0000000..5491791 --- /dev/null +++ b/pl_stat.py @@ -0,0 +1,84 @@ +planet_type = { + "Tempérée" : { + "population" : 100, + }, + "Glacée" : { + "population" : 1 + }, + "Volcanique" : { + "population" : 2 + }, + "Marécageuse" : { + "population" : 10 + }, + "Forestière" : { + "population" : 20 + }, + "Océanique" : { + "population" : 25 + }, + "Oecuménopole" : { + "population" : 2000 + }, + "Désert" : { + "population" : 50 + }, + "Minéralogique" : { + "population" : 3 + }, + "Gazeuse" : { + "population" : 1 + }, + "Acide" : { + "population" : 1 + }, + "Monde usine" : { + "population" : 500 + } +} + +planet_population_type = ( + "Humains", + "Presqu'humains", + "Animaux pacifiques", + "Animaux belliqueux", + "Aliens" +) + +planet_name_prefix = ( + "Acod", "Acht", + "Bex", + "Carob", + "Daris", + "Ecop", + "Fron", + "Glac", "Glad", + "Hac", "Hor", + "Is", + "Jud", + "Kor", + "Ler", + "Marel", + "Naur", + "Olep", + "Prid", "Plex", + "Qef", + "Rem", + "Sarit", + "Thec", "Thex", "Thet", + "Uv", + "Volc", "Vold", + "Wann", + "Xal", + "Yr", + "Zot", +) + +planet_name_sufix = ( + "a Minor", "a Major", "ant", "alor", + "eri", + "inia", "irid", "is" + "o Zion", "or", "oria", + "us", "us Prime", "us Secondus", + "land", "yard" +) \ No newline at end of file diff --git a/planets.py b/planets.py new file mode 100644 index 0000000..cb549eb --- /dev/null +++ b/planets.py @@ -0,0 +1,20 @@ +import random +import pl_stat + +def generate_planet(): + planet_type_generation = random.choice(list(pl_stat.planet_type.keys())) + planet_name = random.choice(pl_stat.planet_name_prefix) + random.choice(pl_stat.planet_name_sufix) + planet_population_people = random.choice(pl_stat.planet_population_type) + planet_population_number = pl_stat.planet_type[planet_type_generation]["population"] * random.randrange(5, 15) / 10 + + planet_description = (f"Planète : {planet_name}\nType : {planet_type_generation}\nPopulation : \n {planet_population_number} milliards\n Majoritairement {planet_population_people}") + return planet_description + +def planet_loop(number): + count = 0 + while count < number: + planet = generate_planet() + print("\n" + planet + "\n\n------------------------------") + count += 1 + +planet_loop(5) \ No newline at end of file diff --git a/planets_db.py b/planets_db.py new file mode 100644 index 0000000..ba70f71 --- /dev/null +++ b/planets_db.py @@ -0,0 +1,60 @@ +import random +import pl_stat +import sqlite3 + +# Connect to SQLite database (or create it if it doesn't exist) +conn = sqlite3.connect('planets.db') +cursor = conn.cursor() + +# Create table for planets if it does not exist +cursor.execute(''' + CREATE TABLE IF NOT EXISTS planets ( + tile TEXT, + name TEXT, + type TEXT, + population_number REAL, + population_type TEXT + ) +''') +conn.commit() + +def generate_planet(tile): + planet_type_generation = random.choice(list(pl_stat.planet_type.keys())) + planet_name = random.choice(pl_stat.planet_name_prefix) + random.choice(pl_stat.planet_name_sufix) + planet_population_people = random.choice(pl_stat.planet_population_type) + planet_population_number = pl_stat.planet_type[planet_type_generation]["population"] * random.randrange(5, 15, 1) / 10 + + # Insert the generated planet into the database + cursor.execute(''' + INSERT INTO planets (tile, name, type, population_number, population_type) + VALUES (?, ?, ?, ?, ?) + ''', (tile, planet_name, planet_type_generation, planet_population_number, planet_population_people)) + + conn.commit() + + planet_description = (f"Tile: {tile}\nPlanète : {planet_name}\nType : {planet_type_generation}\nPopulation : \n {planet_population_number} milliards\n Majoritairement {planet_population_people}") + return planet_description + +def search_tile(tile): + if random.random() < 1/25: + return generate_planet(tile) + else: + return None + +def search_board(): + # Define the grid of tiles + tiles = [(x, y) for x in range(5) for y in range(5)] + + # Simulate searching each tile + results = [] + for tile in tiles: + result = search_tile(tile) + if result: + results.append(result) + + return results + +# Search the board and print results +results = search_board() +for result in results: + print("\n" + result + "\n\n------------------------------") \ No newline at end of file