summaryrefslogtreecommitdiff
path: root/bubbob/test_rnglevel.py
blob: 6b65514ef474d71449c8cf41022d2384a6ace16d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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)