summaryrefslogtreecommitdiff
path: root/bubbob/test_rnglevel.py
diff options
context:
space:
mode:
authorDiego Roversi <diegor@tiscali.it>2019-09-08 18:12:27 +0200
committerDiego Roversi <diegor@tiscali.it>2019-09-08 18:12:27 +0200
commit1d9925c287b318ec21343e2682b51ab6a36ae8db (patch)
tree17d1c0ac21eea6f291146520afa8381db4586fb4 /bubbob/test_rnglevel.py
initial commit from cvs 1.6.2
Diffstat (limited to 'bubbob/test_rnglevel.py')
-rw-r--r--bubbob/test_rnglevel.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/bubbob/test_rnglevel.py b/bubbob/test_rnglevel.py
new file mode 100644
index 0000000..6b65514
--- /dev/null
+++ b/bubbob/test_rnglevel.py
@@ -0,0 +1,64 @@
+#
+# 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,
+ d = {'__name__': 'RandomLevels'}
+ execfile('levels/RandomLevels.py', 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)