This commit is contained in:
Simon Forman 2024-04-14 18:25:42 -07:00
parent 3d5a490c32
commit 7219d6b336
2 changed files with 42 additions and 12 deletions

Binary file not shown.

View File

@ -35,11 +35,19 @@ Stars have what qualities?
'''
from random import randint, expovariate, seed, gauss
from random import randint, expovariate, seed, gauss, lognormvariate
from poisson import poisson
from wordlist import generate_name
ROMAN_NUMBERS = [
None, # no zero, but this aligns entries and their indicies
'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X',
'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII', 'XIX', 'XX',
'XXI', 'XXII', 'XXIII', 'XXIV', 'XXV', 'XXVI', 'XXVII', 'XXVIII', 'XXIX',
]
seed(23)
MINIMUM_DISTANCE_BETWEEN_STARS = 160
@ -58,7 +66,7 @@ TABLES = [
x INTEGER,
y INTEGER,
radius INTEGER,
name TEXT
name TEXT UNIQUE
)''',
('''\
create table planets (
@ -66,6 +74,14 @@ TABLES = [
ordo INTEGER,''' # The order from the star, counting from 1.
# I use "ordo" instead of "order" because "order" is a keyword
# in SQL (or at least it caused a syntax error in SQLite.)
# These capacities are fixed and reflect the conditions on the
# planet in a very abstract way. Bio and Industry should be
# low/high near and far from the star and high/low in the mid-
# range, but for now I'm just going to use random numbers.
'''bio_capacity INTEGER,
industrial_capacity INTEGER,
'''
'''star INTEGER,
FOREIGN KEY(star) REFERENCES stars(id)
)'''),
@ -76,7 +92,11 @@ def init_db(conn):
print('Generating star data.')
c = conn.cursor()
for values in generate_stars(WIDTH, HEIGHT, MINIMUM_DISTANCE_BETWEEN_STARS):
c.execute('insert into stars(x, y, radius, name) values (?, ?, ?, ?)', values)
try:
c.execute('insert into stars(x, y, radius, name) values (?, ?, ?, ?)', values)
except sqlite3.IntegrityError:
print(values) # "Rubbpo"
continue
generate_planets_for_star(c)
c.close()
conn.commit()
@ -93,8 +113,13 @@ def iter_stars(conn):
def generate_stars(width, height, minimum_distance_between_stars):
unique_names = set()
for (x, y) in poisson(width, height, minimum_distance_between_stars):
yield x, y, round(1 + expovariate(1)), generate_name()
name = generate_name()
while name in unique_names:
name = generate_name()
unique_names.add(name)
yield x, y, round(1 + expovariate(1)), name
def how_many_planets():
@ -103,15 +128,20 @@ def how_many_planets():
n = round(gauss(5, 5))
return n
import sqlite3
def generate_planets_for_star(c):
star_id = c.lastrowid
for ordo in range(1, how_many_planets() + 1):
c.execute('insert into planets(ordo, star) values (?, ?)', (ordo, star_id))
c.execute('insert into planets'
'(ordo, star, bio_capacity, industrial_capacity)'
' values (?, ?, ?, ?)',
(
ordo,
star_id,
round(lognormvariate(10, 5)),
round(lognormvariate(10, 5)),
)
)
ROMAN_NUMBERS = [
None, # no zero, but this aligns entries and their indicies
'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X',
'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII', 'XIX', 'XX',
'XXI', 'XXII', 'XXIII', 'XXIV', 'XXV', 'XXVI', 'XXVII', 'XXVIII', 'XXIX',
]