changeset 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 c1f14fa35d30
children 0667189a5973
files gamelib/animal.py
diffstat 1 files changed, 1 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/animal.py	Fri Nov 27 21:13:43 2009 +0000
+++ b/gamelib/animal.py	Fri Nov 27 21:18:18 2009 +0000
@@ -526,11 +526,11 @@
             # We try heading up
             return Position(self.pos.x, self.pos.y, self.pos.z + 1)
         cur_dist = self.target.dist(self.pos)
-        best, min_cost = self._find_min_cost_neighbour(self.target)
         if cur_dist < 2:
             # We're right ontop of our target, so just go there
             return self.target
         # Find the cheapest spot close to us that moves us closer to the target
+        best, min_cost = self._find_min_cost_neighbour(self.target)
         if min_cost < 20 or not self.gameboard.in_bounds(self.pos) \
                 or not self.gameboard.in_bounds(best):
             # If we're not on the gameboard yet, there's no point in looking