Give the stars large id numbers.
Then when you display them they can be mapped to a deterministic human readable format, like letters or some Unicode symbols? Name generators? 🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘 ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓
This commit is contained in:
parent
59f0681494
commit
ddd68e2cb6
BIN
game.sqlite
BIN
game.sqlite
Binary file not shown.
69
stars.py
69
stars.py
|
|
@ -17,7 +17,22 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with game. If not see <http://www.gnu.org/licenses/>.
|
# along with game. If not see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
from random import randint, expovariate, seed
|
'''
|
||||||
|
A field of stars. Each has planets. Each planet has...?
|
||||||
|
|
||||||
|
Keep it simple.
|
||||||
|
|
||||||
|
Stars have what qualities?
|
||||||
|
- Cosmetic
|
||||||
|
- color
|
||||||
|
- brightness
|
||||||
|
- size
|
||||||
|
- Game stats
|
||||||
|
- ?
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
from random import randint, expovariate, seed, getrandbits
|
||||||
from poisson import poisson
|
from poisson import poisson
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -30,21 +45,38 @@ MINIMUM_DISTANCE_BETWEEN_STARS = 160
|
||||||
WIDTH, HEIGHT = 10240, 7680
|
WIDTH, HEIGHT = 10240, 7680
|
||||||
|
|
||||||
|
|
||||||
|
# Database stuff. SQL, etc.
|
||||||
|
|
||||||
|
def generate_list_of_u64_for_ids(n):
|
||||||
|
'''
|
||||||
|
Return a sorted list of n random 64-bit integers
|
||||||
|
(suitable for SQLite rowid columns.)
|
||||||
|
See https://www.sqlite.org/lang_createtable.html#rowid
|
||||||
|
'''
|
||||||
|
result = set()
|
||||||
|
safety = 10
|
||||||
|
while n > 0:
|
||||||
|
canidate = getrandbits(63)
|
||||||
|
while canidate in result:
|
||||||
|
if not safety:
|
||||||
|
raise RuntimeError('this should not happen')
|
||||||
|
safety -= 1
|
||||||
|
canidate = getrandbits(63)
|
||||||
|
result.add(canidate)
|
||||||
|
n -= 1
|
||||||
|
return sorted(result)
|
||||||
|
|
||||||
|
|
||||||
TABLES = [
|
TABLES = [
|
||||||
'create table stars (x INTEGER, y INTEGER, radius INTEGER)',
|
'create table stars (id INTEGER PRIMARY KEY, x INTEGER, y INTEGER, radius INTEGER)',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def generate_stars(width, height, minimum_distance_between_stars):
|
|
||||||
for x, y in poisson(width, height, minimum_distance_between_stars):
|
|
||||||
yield x, y, round(1 + expovariate(1))
|
|
||||||
|
|
||||||
|
|
||||||
def init_db(conn):
|
def init_db(conn):
|
||||||
print('Generating star data.')
|
print('Generating star data.')
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
for values in generate_stars(WIDTH, HEIGHT, MINIMUM_DISTANCE_BETWEEN_STARS):
|
for values in generate_stars(WIDTH, HEIGHT, MINIMUM_DISTANCE_BETWEEN_STARS):
|
||||||
c.execute('insert into stars values (?, ?, ?)', values)
|
c.execute('insert into stars values (?, ?, ?, ?)', values)
|
||||||
c.close()
|
c.close()
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
@ -54,3 +86,24 @@ def iter_stars(conn):
|
||||||
c.execute('select x, y, radius from stars')
|
c.execute('select x, y, radius from stars')
|
||||||
yield from c.fetchall()
|
yield from c.fetchall()
|
||||||
c.close()
|
c.close()
|
||||||
|
|
||||||
|
|
||||||
|
# Procedural Generation of solar system data
|
||||||
|
|
||||||
|
|
||||||
|
def generate_stars(width, height, minimum_distance_between_stars):
|
||||||
|
# we could just call getrandbits(64) here for ID and hope for the best.
|
||||||
|
# it's a large domain (u64) so collisions are unlikely(!).
|
||||||
|
coords = list(poisson(width, height, minimum_distance_between_stars))
|
||||||
|
ids = generate_list_of_u64_for_ids(len(coords))
|
||||||
|
for star_id, (x, y) in zip(ids, coords):
|
||||||
|
yield star_id, x, y, round(1 + expovariate(1))
|
||||||
|
|
||||||
|
|
||||||
|
def how_many_planets():
|
||||||
|
n = round(gauss(5, 5))
|
||||||
|
while n < 0:
|
||||||
|
n = round(gauss(5, 5))
|
||||||
|
return n
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue