Change name Stone to more abstract Blocker.

This commit is contained in:
Niels Serup 2012-08-08 11:53:16 +02:00
parent e759052c60
commit e79b9d20d6
2 changed files with 9 additions and 12 deletions

View File

@ -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))

View File

@ -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)))