# Path: oscar/util/location.py
# class Location:
# 
#     def __init__(self, minimap_loc=None, screen_loc=None, camera_loc=None):
#         self.minimap = minimap_loc
#         self.screen = screen_loc
#         self.camera = camera_loc
# 
#     def compute_minimap_loc(self, obs, shared):
#         scale_x = shared['camera'].width(obs) / shared['screen'].width(obs)
#         scale_y = shared['camera'].height(obs) / shared['screen'].height(obs)
# 
#         self.minimap = shared['minimap'].bound(obs, Point(
#             int(round(self.camera.x - 0.5*shared['camera'].width(obs) + self.screen.x * scale_x)),
#             int(round(self.camera.y - 0.5*shared['camera'].height(obs) + self.screen.y * scale_y))))
# 
#     def squarred_distance(self, other):
#         if not self.minimap or not other.minimap:
#             raise Exception("Can't compute distance")
#         return self.minimap.distance(other.minimap)
# 
#     def distance(self, other):
#         return math.sqrt(self.squarred_distance(other))
# 
#     def equals(self, other):
#         def equals_minimap():
#             return (not self.minimap and not other.minimap) \
#                 or (self.minimap and other.minimap and self.minimap.equals(other.minimap))
# 
#         def equals_screen():
#             return (not self.screen and not other.screen) \
#                 or (self.screen and other.screen and self.screen.equals(other.screen))
# 
#         def equals_camera():
#             return (not self.camera and not other.camera) \
#                 or (self.camera and other.camera and self.camera.equals(other.camera))
# 
#         return equals_minimap() and equals_screen() and equals_camera()
# 
#     def __str__(self):
#         return "Location {\n" \
#                + "  minimap: " + str(self.minimap) + "\n" \
#                + "  screen: " + str(self.screen) + "\n" \
#                + "  camera: " + str(self.camera) + "\n" \
#                + "}"


import numpy as np
import sys
import time
from oscar.constants import *
from oscar.util.location import Location
from oscar.util.coordinates_helper import Coordinates_helper
from oscar.util.exploration_helper import *
from oscar.meta_action import *
                if not self._units_mean_loc or not newLoc.equals(self._units_mean_loc):
                    self._units_mean_loc = newLoc
                    self._is_units_mean_loc_updated = True
        return self._units_mean_loc;

    def _is_units_moving(self, obs):
        self._get_units_mean_location(obs)
        return self._is_units_mean_loc_updated

    def _is_ennemy_visible(self, obs):
        if self._is_ennemies_visible is None:
            ennemies_x, ennemies_y = self._get_ennemies_locations(obs)
            self._is_ennemies_visible = ennemies_x.any()
        return self._is_ennemies_visible

    def _is_target_reached(self, obs):
        _TARGET_REACHED_SQUARED_DISTANCE = 25
        units_mean_loc = self._get_units_mean_location(obs)
        return (not self.target or \
                    units_mean_loc.squarred_distance(self.target) < _TARGET_REACHED_SQUARED_DISTANCE)

    def _get_closest_ennemy(self, obs):
        closest, min_dist = None, None
        ennemies_x, ennemies_y = self._get_ennemies_locations(obs)
        units_mean_loc = self._get_units_mean_location(obs)

        for p in zip(ennemies_x, ennemies_y):
            dist = np.linalg.norm(np.array(units_mean_loc.to_array()) - np.array(p))
            if not min_dist or dist < min_dist:
                closest, min_dist = p, dist

# Path: oscar/util/location.py
# class Location:
# 
#     def __init__(self, minimap_loc=None, screen_loc=None, camera_loc=None):
#         self.minimap = minimap_loc
#         self.screen = screen_loc
#         self.camera = camera_loc
# 
#     def compute_minimap_loc(self, obs, shared):
#         scale_x = shared['camera'].width(obs) / shared['screen'].width(obs)
#         scale_y = shared['camera'].height(obs) / shared['screen'].height(obs)
# 
#         self.minimap = shared['minimap'].bound(obs, Point(
#             int(round(self.camera.x - 0.5*shared['camera'].width(obs) + self.screen.x * scale_x)),
#             int(round(self.camera.y - 0.5*shared['camera'].height(obs) + self.screen.y * scale_y))))
# 
#     def squarred_distance(self, other):
#         if not self.minimap or not other.minimap:
#             raise Exception("Can't compute distance")
#         return self.minimap.distance(other.minimap)
# 
#     def distance(self, other):
#         return math.sqrt(self.squarred_distance(other))
# 
#     def equals(self, other):
#         def equals_minimap():
#             return (not self.minimap and not other.minimap) \
#                 or (self.minimap and other.minimap and self.minimap.equals(other.minimap))
# 
#         def equals_screen():
#             return (not self.screen and not other.screen) \
#                 or (self.screen and other.screen and self.screen.equals(other.screen))
# 
#         def equals_camera():
#             return (not self.camera and not other.camera) \
#                 or (self.camera and other.camera and self.camera.equals(other.camera))
# 
#         return equals_minimap() and equals_screen() and equals_camera()
# 
#     def __str__(self):
#         return "Location {\n" \
#                + "  minimap: " + str(self.minimap) + "\n" \
#                + "  screen: " + str(self.screen) + "\n" \
#                + "  camera: " + str(self.camera) + "\n" \
#                + "}"


# Path: oscar/agent/scripted/minigame/find_and_defeat_zerglings.py
import numpy as np
import sys
import time
from oscar.constants import *
from oscar.util.location import Location
from oscar.util.coordinates_helper import Coordinates_helper
from oscar.util.exploration_helper import *
from oscar.meta_action import *

                if not self._units_mean_loc or not newLoc.equals(self._units_mean_loc):
                    self._units_mean_loc = newLoc
                    self._is_units_mean_loc_updated = True
        return self._units_mean_loc;

    def _is_units_moving(self, obs):
        self._get_units_mean_location(obs)
        return self._is_units_mean_loc_updated

    def _is_ennemy_visible(self, obs):
        if self._is_ennemies_visible is None:
            ennemies_x, ennemies_y = self._get_ennemies_locations(obs)
            self._is_ennemies_visible = ennemies_x.any()
        return self._is_ennemies_visible

    def _is_target_reached(self, obs):
        _TARGET_REACHED_SQUARED_DISTANCE = 25
        units_mean_loc = self._get_units_mean_location(obs)
        return (not self.target or \
                    units_mean_loc.squarred_distance(self.target) < _TARGET_REACHED_SQUARED_DISTANCE)

    def _get_closest_ennemy(self, obs):
        closest, min_dist = None, None
        ennemies_x, ennemies_y = self._get_ennemies_locations(obs)
        units_mean_loc = self._get_units_mean_location(obs)

        for p in zip(ennemies_x, ennemies_y):
            dist = np.linalg.norm(np.array(units_mean_loc.to_array()) - np.array(p))
            if not min_dist or dist < min_dist:
                closest, min_dist = p, dist

        return Location(closest[0], closest[1])