mirror of
https://github.com/abakh/nbsdgames
synced 2025-04-28 14:09:32 -04:00
65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
#
|
|
# This test generates 100 times 25 random levels and checks
|
|
# that it doesn't crash, and that it gives levels that are
|
|
# possible (in the limited sense of not having any full-
|
|
# column walls)
|
|
#
|
|
# this test accepts the following parameters:
|
|
# -wall show the level layout
|
|
# -wind show the level wind pattern
|
|
# -seed N use random seed N for the generation
|
|
#
|
|
|
|
import sys
|
|
import random
|
|
sys.path.append('..')
|
|
sys.path.append('../common')
|
|
|
|
n_lvls = 100
|
|
show_lvl = 0
|
|
|
|
idx = 0
|
|
while idx < len(sys.argv):
|
|
arg = sys.argv[idx]
|
|
idx += 1
|
|
if arg == '-wall':
|
|
show_lvl |= 1
|
|
n_lvls = 2
|
|
if arg == '-wind':
|
|
show_lvl |= 2
|
|
n_lvls = 2
|
|
if arg == '-seed':
|
|
arg = sys.argv[idx]
|
|
idx += 1
|
|
print("Using seed: " + arg + "\n")
|
|
random.seed(arg)
|
|
|
|
def printlvl(level):
|
|
if show_lvl:
|
|
print("\n\n")
|
|
for y in range(level.HEIGHT):
|
|
str = ""
|
|
if show_lvl & 1:
|
|
str = level.walls[y]
|
|
if show_lvl & 2:
|
|
if str:
|
|
str += " | "
|
|
str += level.winds[y]
|
|
print(str)
|
|
|
|
for i in range(n_lvls):
|
|
print('%4d:' % i, end=' ')
|
|
d = {'__name__': 'RandomLevels'}
|
|
exec(compile(open('levels/RandomLevels.py', "rb").read(), 'levels/RandomLevels.py', 'exec'), d)
|
|
for i, Lvl in enumerate(d['GenerateLevels']()):
|
|
level = Lvl(i)
|
|
printlvl(level)
|
|
for x in range(2, level.width-2):
|
|
for y in range(0, level.height):
|
|
if level.walls[y][x] == ' ':
|
|
break
|
|
else:
|
|
for line in level.walls:
|
|
print(line)
|
|
raise AssertionError("full height wall in column %d" % x)
|