From f05a1ab895ceaca9c0ad6dec46e5afbe5a35a1de Mon Sep 17 00:00:00 2001 From: Niels Serup Date: Thu, 9 Aug 2012 14:23:08 +0200 Subject: [PATCH] Fixed rolling stone overanxious transpose bug. --- robotgame/level3.py | 2 +- robotgame/logic/rollingstone.py | 14 +++++++++----- tests/rollingstone_tests.py | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/robotgame/level3.py b/robotgame/level3.py index a044a86..80394d7 100644 --- a/robotgame/level3.py +++ b/robotgame/level3.py @@ -90,7 +90,7 @@ class Level3(level.Level): pos_colour = {} 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 blocks = [ActionBlock(self, 64 * i, 0, action=None, movable=True) diff --git a/robotgame/logic/rollingstone.py b/robotgame/logic/rollingstone.py index 88cea14..8377402 100644 --- a/robotgame/logic/rollingstone.py +++ b/robotgame/logic/rollingstone.py @@ -100,6 +100,7 @@ def generate_simple_playfield(width, height, nturns, nstones, do_transpose = random.choice((True, False)) if do_transpose: width, height = height, width + min_width, min_height = min_height, min_width turns = [((0, 0), None)] stones = [] @@ -142,6 +143,8 @@ def generate_simple_playfield(width, height, nturns, nstones, Right: Down, Up: Left, }.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) playfield = {} @@ -158,12 +161,12 @@ def generate_simple_playfield(width, height, nturns, nstones, playfield[pos] = Blocker 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 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 = {}, [] for pos, val in playfield.items(): if val is Blocker: @@ -172,16 +175,17 @@ def generate_simple_unsolved_solvable_playfield(width, height, nturns, nstones): directions.append(val) 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 of the direction object not returned by that function. You probably want to use this in your game. """ playfield, steps, directions = generate_simple_unsolved_solvable_playfield( - width, height, nturns, nstones) + *args, **kwds) 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): text = [['ยท' for _ in range(width)] for _ in range(height)] diff --git a/tests/rollingstone_tests.py b/tests/rollingstone_tests.py index af78519..fc26e40 100755 --- a/tests/rollingstone_tests.py +++ b/tests/rollingstone_tests.py @@ -36,10 +36,10 @@ class RollingStoneTest(unittest.TestCase): reaches_goal(playfield, 10, 10, steps, (0, 0), (9, 9))) print() - playfield, steps = generate_simple_playfield(10, 10, 4, 11) - print_playfield(playfield, 10, 10, True) + playfield, steps = generate_simple_playfield(10, 15, 4, 150) + print_playfield(playfield, 10, 15, False) 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__': unittest.main()