def update_enemy_hills(self): try: new_enemy_hills = self.ants.enemy_hills() self.num_enemy_hills = len(new_enemy_hills) hill_set = set() # Add new hill scans for hill_loc, owner in new_enemy_hills: hill_set.add(hill_loc) if hill_loc not in self.enemy_hills[owner]: self.enemy_hill_scans.add(hill_scan(self, hill_loc, owner)) self.enemy_hills[owner].add(hill_loc) self.enemy_hills[0].add(hill_loc) # Remove razed hills for index in range(1, len(self.enemy_hills)): for hill_loc in self.enemy_hills[index].copy(): row, col = hill_loc if self.vision[row][col] and hill_loc not in hill_set: for scan in self.enemy_hill_scans.copy(): if scan.loc == hill_loc: self.enemy_hill_scans.remove(scan) self.enemy_hills[index].remove(hill_loc) self.enemy_hills[0].remove(hill_loc) except: self.logger.error("Error update enemy hills: print_exc(): %s", traceback.format_exc())
def update_my_hills(self): try: new_hills = set(self.ants.my_hills()) self.num_my_hills = len(new_hills) # Add new hill scans for hill_loc in new_hills: if hill_loc not in self.my_hills: self.my_hill_scans.add(hill_scan(self, hill_loc, 0)) # Remove razed hills for hill_loc in self.my_hills: if hill_loc not in new_hills: for scan in self.my_hill_scans.copy(): if scan.loc == hill_loc: self.my_hill_scans.remove(scan) self.my_hills = new_hills except: self.logger.error("Error update my ants: print_exc(): %s", traceback.format_exc())