comparison gamelib/animal.py @ 531:452cde9af2a2

Fix order of checks to avoid unneeded work
author Neil Muller <drnlmuller@gmail.com>
date Fri, 27 Nov 2009 21:18:18 +0000
parents a42852e50df1
children 7addf41b6abb
comparison
equal deleted inserted replaced
530:c1f14fa35d30 531:452cde9af2a2
524 if self.target.x == self.pos.x and self.target.y == self.pos.y and \ 524 if self.target.x == self.pos.x and self.target.y == self.pos.y and \
525 self.target.z > self.pos.z: 525 self.target.z > self.pos.z:
526 # We try heading up 526 # We try heading up
527 return Position(self.pos.x, self.pos.y, self.pos.z + 1) 527 return Position(self.pos.x, self.pos.y, self.pos.z + 1)
528 cur_dist = self.target.dist(self.pos) 528 cur_dist = self.target.dist(self.pos)
529 best, min_cost = self._find_min_cost_neighbour(self.target)
530 if cur_dist < 2: 529 if cur_dist < 2:
531 # We're right ontop of our target, so just go there 530 # We're right ontop of our target, so just go there
532 return self.target 531 return self.target
533 # Find the cheapest spot close to us that moves us closer to the target 532 # Find the cheapest spot close to us that moves us closer to the target
533 best, min_cost = self._find_min_cost_neighbour(self.target)
534 if min_cost < 20 or not self.gameboard.in_bounds(self.pos) \ 534 if min_cost < 20 or not self.gameboard.in_bounds(self.pos) \
535 or not self.gameboard.in_bounds(best): 535 or not self.gameboard.in_bounds(best):
536 # If we're not on the gameboard yet, there's no point in looking 536 # If we're not on the gameboard yet, there's no point in looking
537 # for an optimal path. 537 # for an optimal path.
538 return best 538 return best