First commit

This commit is contained in:
gauvainboiche
2024-12-05 15:56:08 +01:00
commit 94c3c2a44f
4 changed files with 164 additions and 0 deletions

Binary file not shown.

84
pl_stat.py Normal file
View File

@@ -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"
)

20
planets.py Normal file
View File

@@ -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)

60
planets_db.py Normal file
View File

@@ -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------------------------------")