Commits

Lars Yencken committed 365c547

Don't plan paths outside the frontier.

Comments (0)

Files changed (1)

         self.targets = {}
         self.orders = {}
         self.needs_orders = set(ants.my_ants())
+        self.frontier = self.build_frontier(self.game.unseen)
 
         # prevent stepping on own hill
         for hill_loc in ants.my_hills():
         "A* search from the location to the destination."
         dest_d = partial(self.ants.distance, dest)
         passable = self.ants.passable
+        unseen = self.game.unseen
+        frontier = self.frontier
         def f(p):
             return dest_d(p[-1]) + len(p)
 
             l0 = p[-1]
             for direction in ('n', 's', 'e', 'w'):
                 l = self.ants.destination(l0, direction)
-                if l not in p and l not in self.orders and passable(l):
+                if l not in p and l not in self.orders and passable(l) \
+                        and (l not in unseen or l in frontier):
                     yield p + (l,)
 
         p0 = loc,
     def explore(self):
         # explore unseen areas
         distance = self.ants.distance
-        frontier = self.build_frontier(self.game.unseen)
         for ant_loc in list(self.needs_orders):
             unseen_dist = []
-            for unseen_loc in frontier:
+            for unseen_loc in self.frontier:
                 dist = distance(ant_loc, unseen_loc)
                 unseen_dist.append((dist, unseen_loc))
             unseen_dist.sort()