Merge branch 'master' of hongabar.org:robotgame

This commit is contained in:
Sakse Dalum 2012-08-09 14:27:00 +02:00
commit c22619b81f
3 changed files with 13 additions and 9 deletions

View File

@ -90,7 +90,7 @@ class Level3(level.Level):
pos_colour = {} pos_colour = {}
for box, (x, y) in zip(boxes, itertools.product(range(3, 6), range(3, 6))): for box, (x, y) in zip(boxes, itertools.product(range(3, 6), range(3, 6))):
self.tiles.append(tile.Tile(self, x * 64, (y + 1) * 48, self.imgs['ground1'])) self.tiles.append(tile.Tile(self, x * 64, y * 48, self.imgs['ground1']))
pos_colour[(x, y)] = box pos_colour[(x, y)] = box
blocks = [ActionBlock(self, 64 * i, 0, action=None, movable=True) blocks = [ActionBlock(self, 64 * i, 0, action=None, movable=True)

View File

@ -100,6 +100,7 @@ def generate_simple_playfield(width, height, nturns, nstones,
do_transpose = random.choice((True, False)) do_transpose = random.choice((True, False))
if do_transpose: if do_transpose:
width, height = height, width width, height = height, width
min_width, min_height = min_height, min_width
turns = [((0, 0), None)] turns = [((0, 0), None)]
stones = [] stones = []
@ -142,6 +143,8 @@ def generate_simple_playfield(width, height, nturns, nstones,
Right: Down, Right: Down,
Up: Left, Up: Left,
}.get(d)) for ((x, y), d) in turns] }.get(d)) for ((x, y), d) in turns]
width, height = height, width
min_width, min_height = min_height, min_width
used_fields = _fields_from_turns(turns) used_fields = _fields_from_turns(turns)
playfield = {} playfield = {}
@ -158,12 +161,12 @@ def generate_simple_playfield(width, height, nturns, nstones,
playfield[pos] = Blocker playfield[pos] = Blocker
return playfield, len(used_fields) - 1 return playfield, len(used_fields) - 1
def generate_simple_unsolved_solvable_playfield(width, height, nturns, nstones): def generate_simple_unsolved_solvable_playfield(*args, **kwds):
""" """
Return a tuple of a playfield without direction objects, its number of Return a tuple of a playfield without direction objects, its number of
steps, and a list of the direction objects. steps, and a list of the direction objects.
""" """
playfield, steps = generate_simple_playfield(width, height, nturns, nstones) playfield, steps = generate_simple_playfield(*args, **kwds)
new_playfield, directions = {}, [] new_playfield, directions = {}, []
for pos, val in playfield.items(): for pos, val in playfield.items():
if val is Blocker: if val is Blocker:
@ -172,16 +175,17 @@ def generate_simple_unsolved_solvable_playfield(width, height, nturns, nstones):
directions.append(val) directions.append(val)
return new_playfield, steps, directions return new_playfield, steps, directions
def generate_simple_unsolved_solvable_extra(width, height, nturns, nstones): def generate_simple_unsolved_solvable_extra(*args, **kwds):
""" """
Do the same as generate_simple_unsolved_solvable, but throw in some copies Do the same as generate_simple_unsolved_solvable, but throw in some copies
of the direction object not returned by that function. You probably want to of the direction object not returned by that function. You probably want to
use this in your game. use this in your game.
""" """
playfield, steps, directions = generate_simple_unsolved_solvable_playfield( playfield, steps, directions = generate_simple_unsolved_solvable_playfield(
width, height, nturns, nstones) *args, **kwds)
missing_dir = list(set(all_directions) - set(directions))[0] missing_dir = list(set(all_directions) - set(directions))[0]
return playfield, steps, directions + [missing_dir] * (len(directions) / 3) return playfield, steps, directions + \
[missing_dir] * (len(directions) / 3) + [Right]
def print_playfield(playfield, width, height, hide_directions): def print_playfield(playfield, width, height, hide_directions):
text = [['·' for _ in range(width)] for _ in range(height)] text = [['·' for _ in range(width)] for _ in range(height)]

View File

@ -36,10 +36,10 @@ class RollingStoneTest(unittest.TestCase):
reaches_goal(playfield, 10, 10, steps, (0, 0), (9, 9))) reaches_goal(playfield, 10, 10, steps, (0, 0), (9, 9)))
print() print()
playfield, steps = generate_simple_playfield(10, 10, 4, 11) playfield, steps = generate_simple_playfield(10, 15, 4, 150)
print_playfield(playfield, 10, 10, True) print_playfield(playfield, 10, 15, False)
self.assertTrue( self.assertTrue(
reaches_goal(playfield, 10, 10, steps, (0, 0), (9, 9))) reaches_goal(playfield, 10, 15, steps, (0, 0), (9, 14)))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()