1. Lars Yencken
  2. aichallenge-py

Commits

Lars Yencken  committed 1a0d472

Cutoff search by depth rather than queue len.

  • Participants
  • Parent commits 9420122
  • Branches master

Comments (0)

Files changed (1)

File MyBot.py

View file
                 return True
         return False
 
-    def find_path(self, loc, dest):
+    def find_path(self, loc, dest, max_depth=50):
         "A* search from the location to the destination."
         dest_d = partial(self.ants.distance, dest)
         passable = self.ants.passable
         pop = partial(heapq.heappop, queue)
 
         visited = set()
+        d = 0
         while queue:
+            d += 1
             cost, p = pop()
             if p[-1] == dest:
                 return p[1:]
 
+            if d >= max_depth:
+                # randomly choose between the best options so far
+                push((cost, p))
+                p = random.choice([v for v in queue if v[0] == cost])[1]
+                return p[1:]
+
             for p_next in expand(p):
                 l_next = p_next[-1]
                 step = len(p)
                     visited.add(l_next)
                     push((f(p_next), p_next))
 
-            if len(queue) > 100:
-                # randomly choose between the best options so far
-                push((cost, p))
-                p = random.choice([v for v in queue if v[0] ==
-                        cost])[1]
-                return p[1:]
-
     def find_food(self):
         ant_dist = []
         distance = self.ants.distance