Mercurial > rinkhals
changeset 72:aa4bd93575d9
Fix some bound checking and tweak movement costs
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 22:44:21 +0000 |
parents | 00cf9d7f22dc |
children | f3ce3346e25e |
files | gamelib/animal.py |
diffstat | 1 files changed, 11 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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)