def get_move(self): # if we were killed, for whatever reason, reset the path if self.current_pos == self.initial_pos: self.current_path = self.path_to_border # if we are not currently tracking anything if not self.tracking: # check the enemy positions possible_targets = [enemy for enemy in self.enemy_bots if self.team.in_zone(enemy.current_pos)] if possible_targets: # get the path to the closest one closest_enemy = min([(len(self.adjacency.a_star(self.current_pos, enemy.current_pos)),enemy) for enemy in possible_targets]) # track that bot by using its index self.tracking = closest_enemy[1].index else: # otherwise keep going if we aren't already underway if not self.path: self.path = self.path_to_border elif self.tracking: # if the enemy is no longer in our zone if not self.team.in_zone(self.tracking_target.current_pos): self.tracking = None self.path = self.path_to_border # otherwise update the path to the target else: self.path = self.path_to_target # if something above went wrong, just stand still if not self.path: return stop else: return diff_pos(self.current_pos, self.path.pop())
def get_move(self): if self.current_pos == self.initial_pos: # we have probably been killed # reset the path self.current_path = None if not self.current_path: self.current_path = self.bfs_food() new_pos = self.current_path.pop() return diff_pos(self.current_pos, new_pos)