From e79b9d20d676da24dc466d1eed7d33598de5abab Mon Sep 17 00:00:00 2001 From: Niels Serup Date: Wed, 8 Aug 2012 11:53:16 +0200 Subject: [PATCH] Change name Stone to more abstract Blocker. --- robotgame/logic/rollingstone.py | 15 ++++++--------- tests/rollingstone_tests.py | 6 +++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/robotgame/logic/rollingstone.py b/robotgame/logic/rollingstone.py index 336b342..35f2859 100644 --- a/robotgame/logic/rollingstone.py +++ b/robotgame/logic/rollingstone.py @@ -34,10 +34,7 @@ import itertools from robotgame.logic.direction import * import random -class RollingStoneError(Exception): - pass - -class Stone(object): +class Blocker(object): pass def step(playfield, width, height, old_pos, direc): @@ -47,7 +44,7 @@ def step(playfield, width, height, old_pos, direc): """ pos = direc.next_pos(old_pos) x, y = pos - if playfield.get(pos) is Stone or x < 0 or x >= width \ + if playfield.get(pos) is Blocker or x < 0 or x >= width \ or y < 0 or y >= height: pos = old_pos elif isDirection(playfield.get(pos)): @@ -81,7 +78,7 @@ def generate_simple_playfield(width, height, nturns, nstones): * the playfield is completable in nturns or less * the playfield has at most nstones stones - Return (playfield : {(x, y): Direction | Stone}, + Return (playfield : {(x, y): Direction | Blocker}, steps : int) where (x, y) : (int, int) @@ -151,7 +148,7 @@ def generate_simple_playfield(width, height, nturns, nstones): break pos = random.choice(list(emptys)) emptys.remove(pos) - playfield[pos] = Stone + playfield[pos] = Blocker return playfield, len(used_fields) - 1 def generate_simple_unsolved_solvable_playfield(width, height, nturns, nstones): @@ -162,7 +159,7 @@ def generate_simple_unsolved_solvable_playfield(width, height, nturns, nstones): playfield = generate_simple_playfield(width, height, nturns, stones) new_playfield, directions = {}, [] for pos, val in playfield.items(): - if val is Stone: + if val is Blocker: new_playfield[pos] = val else: directions.append(val) @@ -184,7 +181,7 @@ def print_playfield(playfield, width, height, hide_directions): for (x, y), val in playfield.items(): if isDirection(val) and hide_directions: continue - text[y][x] = '%' if val == Stone else repr(val).rsplit('.', 1)[1][0] \ + text[y][x] = '%' if val == Blocker else repr(val).rsplit('.', 1)[1][0] \ if isDirection(val) else 'G' print('\n'.join(''.join(line) for line in text)) diff --git a/tests/rollingstone_tests.py b/tests/rollingstone_tests.py index 172d84b..ec94472 100644 --- a/tests/rollingstone_tests.py +++ b/tests/rollingstone_tests.py @@ -10,15 +10,15 @@ class RollingStoneTest(unittest.TestCase): playfield_example_succeed = { (0, 0): Down, (0, 2): Right, - (1, 3): Stone, - (2, 1): Stone, + (1, 3): Blocker, + (2, 1): Blocker, (2, 2): Down, (2, 3): Right, } self.assertTrue(reaches_goal(playfield_example_succeed, 4, 4, 100, (0, 0), (3, 3))) - playfield_example_succeed[(1, 2)] = Stone + playfield_example_succeed[(1, 2)] = Blocker self.assertFalse(reaches_goal(playfield_example_succeed, 4, 4, 100, (0, 0), (3, 3)))