From 94c3c2a44f26d2a324fe4c616795824f058f903e Mon Sep 17 00:00:00 2001 From: gauvainboiche Date: Thu, 5 Dec 2024 15:56:08 +0100 Subject: [PATCH] First commit --- __pycache__/pl_stat.cpython-312.pyc | Bin 0 -> 1093 bytes pl_stat.py | 84 ++++++++++++++++++++++++++++ planets.py | 20 +++++++ planets_db.py | 60 ++++++++++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 __pycache__/pl_stat.cpython-312.pyc create mode 100644 pl_stat.py create mode 100644 planets.py create mode 100644 planets_db.py diff --git a/__pycache__/pl_stat.cpython-312.pyc b/__pycache__/pl_stat.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5ec8abaf7df7b3a4baa910036f175787edd0aa71 GIT binary patch literal 1093 zcmYjPyKWOf6y2xo*iM{8v3WJ7K*$XR9T7q}PxHtFk`S;gtjX@g8MHgInc0bKS9}5; z4J{J>0e-+GO=zd3N@o`x>zWSE+OBdJA?1Wst z2lCkptZ<_QaA16I2jK3aDXNBSep?FfUEo) z76pisQ;B5}^eqG}0qS5Wuq=SE!8jHv8Ghr~`0T*3NxvS#4i02I98i|9XzaW;90<%) zIj7wSg-jH&jt)@SP1M)M%C83`#Qnk+qam(JK`5^ID%+4TB2@I}b|Ldr-anbti*-t3 zB)ioF1>{&;iT*$B2uG2*ephAc5y4c{?kcYyuu$Vks@xUaRsJgC>`3`*h!df_^?)VH z+u)2UPmjW2sN4onx52n_o(bhXmms}>%6*Bs@?kbOQr` zAs%kmJXJ`b#%Vk4C0JD^#s6&^>x&beq8PUmj*m%KElg`df;6x$;fq^WkHY2F0c?P1 zZK6X$Tl*ZH!MAIzvJkh%r$oDhDduLOL28Q>r4N$cRqk=jLK)#Fdz)+!8&mqU&&?^%X}vVj^&QHY-|P0h hlJl`J+O{*dopY-)n!i(l-^I~#w(R`07Wh-R`d{g3W$6F_ literal 0 HcmV?d00001 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