# 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 *
            return move_camera(self._loc_in_minimap, self.coordinates_helper)[0]

        elif state == States.ATTACK__MOVE_UNITS_TO_CLOSEST_ENNEMY:
            return actions.FunctionCall(ATTACK_SCREEN, [NOT_QUEUED, self._get_closest_ennemy(obs).to_array()])

        elif state == States.ATTACK__CENTER_CAMERA_ON_UNITS:
            self._loc_in_minimap = self._get_minimap_loc_centered_on_units(obs)
            return move_camera(self._loc_in_minimap, self.coordinates_helper)[0]

    def _get_loc_in_minimap(self, obs):
        if not self._loc_in_minimap:
            self._loc_in_minimap = self.coordinates_helper.get_loc_in_minimap(obs)
        return self._loc_in_minimap

    def _get_ennemies_locations(self, obs):
        if self._ennemies_x is None or self._ennemies_y is None:
            player_relative = obs.observation[SCREEN][SCREEN_PLAYER_RELATIVE]
            self._ennemies_y, self._ennemies_x = (player_relative == PLAYER_HOSTILE).nonzero()
        return self._ennemies_x, self._ennemies_y

    def _get_units_locations(self, obs):
        if self._units_x is None or not self._units_y is None:
            player_relative = obs.observation[SCREEN][SCREEN_PLAYER_RELATIVE]
            self._units_y, self._units_x = (player_relative == PLAYER_SELF).nonzero()
        return self._units_x, self._units_y

    def _get_units_mean_location(self, obs):
        if not self._is_units_mean_loc_updated:
            units_x, units_y = self._get_units_locations(obs) 
            if units_x.size > 0:

# 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 *

            return move_camera(self._loc_in_minimap, self.coordinates_helper)[0]

        elif state == States.ATTACK__MOVE_UNITS_TO_CLOSEST_ENNEMY:
            return actions.FunctionCall(ATTACK_SCREEN, [NOT_QUEUED, self._get_closest_ennemy(obs).to_array()])

        elif state == States.ATTACK__CENTER_CAMERA_ON_UNITS:
            self._loc_in_minimap = self._get_minimap_loc_centered_on_units(obs)
            return move_camera(self._loc_in_minimap, self.coordinates_helper)[0]

    def _get_loc_in_minimap(self, obs):
        if not self._loc_in_minimap:
            self._loc_in_minimap = self.coordinates_helper.get_loc_in_minimap(obs)
        return self._loc_in_minimap

    def _get_ennemies_locations(self, obs):
        if self._ennemies_x is None or self._ennemies_y is None:
            player_relative = obs.observation[SCREEN][SCREEN_PLAYER_RELATIVE]
            self._ennemies_y, self._ennemies_x = (player_relative == PLAYER_HOSTILE).nonzero()
        return self._ennemies_x, self._ennemies_y

    def _get_units_locations(self, obs):
        if self._units_x is None or not self._units_y is None:
            player_relative = obs.observation[SCREEN][SCREEN_PLAYER_RELATIVE]
            self._units_y, self._units_x = (player_relative == PLAYER_SELF).nonzero()
        return self._units_x, self._units_y

    def _get_units_mean_location(self, obs):
        if not self._is_units_mean_loc_updated:
            units_x, units_y = self._get_units_locations(obs) 
            if units_x.size > 0:

                newLoc = Location(int(units_x.mean()), int(units_y.mean()))