1. Lars Yencken
  2. aichallenge-py

Commits

Lars Yencken  committed 8ba44b7

Ignore defeated enemy hills.

  • Participants
  • Parent commits 50d1d96
  • Branches scent

Comments (0)

Files changed (1)

File MyBot.py

View file
  • Ignore whitespace
 from functools import partial
 from itertools import product
 import random
+import Image
 
 import numpy as np
 from scipy.signal import convolve
     def attack_hills(self):
         # attack enemy hills
         ant_dist = []
-        distance = self.ants.distance
-        for hill_loc in self.game.hills:
-            for ant_loc in list(self.needs_orders):
-                dist = distance(ant_loc, hill_loc)
-                ant_dist.append((dist, ant_loc))
+        for hill_loc in self.game.enemy_hills.difference(
+                self.game.destroyed_hills):
+            for ant in list(self.needs_orders):
+                dist = ant.distance(hill_loc)
+                ant_dist.append((dist, ant))
         ant_dist.sort()
         for dist, ant_loc in ant_dist:
             if ant_loc in self.needs_orders:
         self.seen = np.zeros((self.rows, self.cols), dtype=np.bool_)
         self.plannable = np.zeros((self.rows, self.cols), dtype=np.bool_)
         self.scent = np.zeros((self.rows, self.cols), dtype=np.int32)
+        self.destroyed_hills = set()
+        self.enemy_hills = set()
 
     def do_turn(self, ants):
         "Give orders to all of our ants."
         for hill_loc, hill_owner in ants.enemy_hills():
             if hill_loc not in self.hills:
                 self.hills.append(hill_loc)
-    
+            self.enemy_hills.add(hill_loc)
+
+        self.destroyed_hills.update(self.enemy_hills.intersection(
+            ants.my_ants()))
+
     def waft(self, ants):
         "Combine old scents with new ones."
         rows = ants.rows
             l = u''.join(render((i, j)) for j in xrange(self.cols))
             print >> sys.stderr, l
 
+def dump_grayscale_image(m, filename):
+    rows, cols = m.shape
+    im = Image.new('1', (cols, rows))
+    for y, x in zip(*np.nonzero(m)):
+        im.putpixel((x, y), 1)
+    im.save(filename)
+    
 if __name__ == '__main__':
     args = sys.argv[1:]
     # psyco will speed up python a little, but is not needed