comparison gamelib/animal.py @ 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 bf28f499c6b4
comparison
equal deleted inserted replaced
71:00cf9d7f22dc 72:aa4bd93575d9
61 61
62 costs = { 62 costs = {
63 # weighting for movement calculation 63 # weighting for movement calculation
64 'grassland' : 2, 64 'grassland' : 2,
65 'woodland' : 1, # Try to keep to the woods if possible 65 'woodland' : 1, # Try to keep to the woods if possible
66 'broken fence' : 1, 66 'broken fence' : 2,
67 'fence' : 10, 67 'fence' : 10,
68 'guardtower' : 1, # We can pass under towers 68 'guardtower' : 2, # We can pass under towers
69 'henhouse' : 1, 69 'henhouse' : 2,
70 } 70 }
71 71
72 def __init__(self, pos): 72 def __init__(self, pos):
73 image_left = imagecache.load_image('sprites/fox.png') 73 image_left = imagecache.load_image('sprites/fox.png')
74 image_right = imagecache.load_image('sprites/fox.png', 74 image_right = imagecache.load_image('sprites/fox.png',
179 if blocked: 179 if blocked:
180 # find the closest point in moves to new_pos that's not a fence 180 # find the closest point in moves to new_pos that's not a fence
181 final_pos = None 181 final_pos = None
182 dist = 10 182 dist = 10
183 for poss in moves: 183 for poss in moves:
184 this_tile = gameboard.tv.get(poss.to_tuple()) 184 if gameboard.in_bounds(poss):
185 this_tile = gameboard.tv.get(poss.to_tuple())
186 else:
187 this_tile = tiles.REVERSE_TILE_MAP['woodland']
185 new_dist = poss.dist(new_pos) 188 new_dist = poss.dist(new_pos)
186 if new_dist < dist: 189 if new_dist < dist:
187 dist = new_dist 190 dist = new_dist
188 final_pos = poss 191 final_pos = poss
189 this_tile = gameboard.tv.get(final_pos.to_tuple()) 192 if gameboard.in_bounds(final_pos):
193 this_tile = gameboard.tv.get(final_pos.to_tuple())
194 else:
195 this_tile = tiles.REVERSE_TILE_MAP['woodland']
190 if tiles.TILE_MAP[this_tile] == 'broken fence' and self.hunting: 196 if tiles.TILE_MAP[this_tile] == 'broken fence' and self.hunting:
191 # We'll head back towards the holes we make/find 197 # We'll head back towards the holes we make/find
192 self.landmarks.append(final_pos) 198 self.landmarks.append(final_pos)
193 elif tiles.TILE_MAP[this_tile] == 'fence' and not self.dig_pos: 199 elif tiles.TILE_MAP[this_tile] == 'fence' and not self.dig_pos:
194 self.tick = 5 200 self.tick = 5