Commits

Lars Yencken committed 06ed50c

Fix a bug in remembering destroyed hills.

  • Participants
  • Parent commits ec8df08
  • Branches scent
  • Tags list, v11

Comments (0)

Files changed (1)

     def attack_hills(self):
         # attack enemy hills
         ant_dist = []
-        for hill_loc in self.game.enemy_hills.difference(
-                self.game.destroyed_hills):
+        for hill_loc in self.active_enemy_hills:
             for ant in list(self.needs_orders):
                 dist = ant.distance(hill_loc)
                 ant_dist.append((dist, ant))
         self.cols = ants.cols
         self.seen = np.zeros((self.rows, self.cols), dtype=np.bool_)
         self.plannable = np.zeros((self.rows, self.cols), dtype=np.bool_)
-        self.destroyed_hills = set()
         self.enemy_hills = set()
+        self.destroyed_hills = set()
         self.turn_no = 0
 
     def do_turn(self, ants):
                     plannable[loc] = True
 
     def remember_hills(self, ants):
-        my_ants = set(ants.my_ants())
-        for hill in ants.enemy_hills():
-            if hill.loc in my_ants:
-                self.destroyed_hills.add(hill.loc)
-            elif hill.loc not in self.destroyed_hills:
-                self.enemy_hills.add(hill.loc)
+        self.enemy_hills.update(h.loc for h in ants.enemy_hills())
+        self.destroyed_hills.update(self.enemy_hills.intersection(
+                ants.my_ants()))
+
+    @property
+    def active_enemy_hills(self):
+        return self.enemy_hills.difference(self.destroyed_hills)
 
     def get_reward_matrix(self, frontier, ants):
         reward = np.ones((ants.rows, ants.cols), dtype=np.float32) * -1
 
-        for hill in self.enemy_hills.difference(self.destroyed_hills):
-            reward[hill] = 30
+        for loc in self.active_enemy_hills:
+            reward[loc] = 30
 
         for food in ants.food():
             reward[food] = 15