# HG changeset patch # User Neil Muller # Date 1251758661 0 # Node ID aa4bd93575d973942253a795e63de22ae20dafb7 # Parent 00cf9d7f22dca8835b252cf59d65f4652b64c18a Fix some bound checking and tweak movement costs diff -r 00cf9d7f22dc -r aa4bd93575d9 gamelib/animal.py --- a/gamelib/animal.py Mon Aug 31 22:20:27 2009 +0000 +++ b/gamelib/animal.py Mon Aug 31 22:44:21 2009 +0000 @@ -63,10 +63,10 @@ # weighting for movement calculation 'grassland' : 2, 'woodland' : 1, # Try to keep to the woods if possible - 'broken fence' : 1, + 'broken fence' : 2, 'fence' : 10, - 'guardtower' : 1, # We can pass under towers - 'henhouse' : 1, + 'guardtower' : 2, # We can pass under towers + 'henhouse' : 2, } def __init__(self, pos): @@ -181,12 +181,18 @@ final_pos = None dist = 10 for poss in moves: - this_tile = gameboard.tv.get(poss.to_tuple()) + if gameboard.in_bounds(poss): + this_tile = gameboard.tv.get(poss.to_tuple()) + else: + this_tile = tiles.REVERSE_TILE_MAP['woodland'] new_dist = poss.dist(new_pos) if new_dist < dist: dist = new_dist final_pos = poss - this_tile = gameboard.tv.get(final_pos.to_tuple()) + if gameboard.in_bounds(final_pos): + this_tile = gameboard.tv.get(final_pos.to_tuple()) + else: + this_tile = tiles.REVERSE_TILE_MAP['woodland'] if tiles.TILE_MAP[this_tile] == 'broken fence' and self.hunting: # We'll head back towards the holes we make/find self.landmarks.append(final_pos)