# Path: oscar/util/unit.py
# class Unit:
# 
#     def __init__(self, location, unit_id=None, player_id=None):
#         self.location = location
#         self.unit_id = unit_id
#         self.player_id = player_id
# 
#     def equals(self, other):
#         def is_same_location():
#             return (not self.location and not other.location) \
#                 or (self.location and other.location and self.location.equals(other.location))
#         def is_same_unit_id():
#             return (self.unit_id is None and other.unit_id is None) \
#                 or (self.unit_id is not None and other.unit_id is not None and self.unit_id == other.unit_id)
#         def is_same_player_id():
#             return (self.player_id is None and other.player_id is None) \
#                 or (self.player_id is not None and other.player_id is not None and self.player_id == other.player_id)
#         
#         return is_same_location() and is_same_unit_id() and is_same_player_id()
# 
# 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/util/point.py
# class Point:
# 
#     def __init__(self, x=None, y=None):
#         self.x = x
#         self.y = y
# 
#     def squared_distance(self, other):
#         return (self.x-other.x)*(self.x-other.x) + (self.y-other.y)*(self.y-other.y)
# 
#     def distance(self, other):
#         return math.sqrt(self.squared_distance(other))
# 
#     def get_flipped(self):
#         return Point(self.y, self.x)
# 
#     def to_array(self):
#         return [self.x, self.y]
# 
#     def equals(self, other):
#         return self.x == other.x and self.y == other.y
# 
#     def difference(self, other):
#         return Point(self.x - other.x, self.y - other.y)
# 
#     def addition(self, other):
#         return Point(self.x + other.x, self.y + other.y)
# 
#     def __str__(self):
#         return "Point("+str(self.x)+","+str(self.y)+")"


import numpy as np
from oscar.constants import *
from oscar.util.unit import Unit
from oscar.util.location import Location
from oscar.util.point import Point
                while len(queue) > 0:
                    cur = queue.pop()
                    if _try_explore(cur[0]+1, cur[1], queue, scanned):
                        sum_x += cur[0]+1
                        sum_y += cur[1]
                        nb_scanned += 1
                    if _try_explore(cur[0], cur[1]+1, queue, scanned):
                        sum_x += cur[0]
                        sum_y += cur[1]+1
                        nb_scanned += 1
                    if _try_explore(cur[0], cur[1]-1, queue, scanned):
                        sum_x += cur[0]
                        sum_y += cur[1]-1
                        nb_scanned += 1

                return round(sum_x/nb_scanned), round(sum_y/nb_scanned)

            screen_width = Screen.width(obs)
            screen_height = Screen.height(obs)
            scanned = np.zeros((screen_width, screen_height))
            self._scanned_units = []

            for x in range(screen_width):
                for y in range(screen_height):
                    if scanned[x, y] == 0 and obs.observation[SCREEN][SCREEN_UNIT_TYPE][x, y] != 0:
                        center_x, center_y = _explore_contiguous(x, y,
                                                                 obs.observation[SCREEN][SCREEN_UNIT_TYPE][x, y],
                                                                 obs.observation[SCREEN][SCREEN_PLAYER_RELATIVE][x, y],
                                                                 scanned)


# Path: oscar/util/unit.py
# class Unit:
# 
#     def __init__(self, location, unit_id=None, player_id=None):
#         self.location = location
#         self.unit_id = unit_id
#         self.player_id = player_id
# 
#     def equals(self, other):
#         def is_same_location():
#             return (not self.location and not other.location) \
#                 or (self.location and other.location and self.location.equals(other.location))
#         def is_same_unit_id():
#             return (self.unit_id is None and other.unit_id is None) \
#                 or (self.unit_id is not None and other.unit_id is not None and self.unit_id == other.unit_id)
#         def is_same_player_id():
#             return (self.player_id is None and other.player_id is None) \
#                 or (self.player_id is not None and other.player_id is not None and self.player_id == other.player_id)
#         
#         return is_same_location() and is_same_unit_id() and is_same_player_id()
# 
# 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/util/point.py
# class Point:
# 
#     def __init__(self, x=None, y=None):
#         self.x = x
#         self.y = y
# 
#     def squared_distance(self, other):
#         return (self.x-other.x)*(self.x-other.x) + (self.y-other.y)*(self.y-other.y)
# 
#     def distance(self, other):
#         return math.sqrt(self.squared_distance(other))
# 
#     def get_flipped(self):
#         return Point(self.y, self.x)
# 
#     def to_array(self):
#         return [self.x, self.y]
# 
#     def equals(self, other):
#         return self.x == other.x and self.y == other.y
# 
#     def difference(self, other):
#         return Point(self.x - other.x, self.y - other.y)
# 
#     def addition(self, other):
#         return Point(self.x + other.x, self.y + other.y)
# 
#     def __str__(self):
#         return "Point("+str(self.x)+","+str(self.y)+")"


# Path: oscar/shared/screen.py
import numpy as np
from oscar.constants import *
from oscar.util.unit import Unit
from oscar.util.location import Location
from oscar.util.point import Point

                while len(queue) > 0:
                    cur = queue.pop()
                    if _try_explore(cur[0]+1, cur[1], queue, scanned):
                        sum_x += cur[0]+1
                        sum_y += cur[1]
                        nb_scanned += 1
                    if _try_explore(cur[0], cur[1]+1, queue, scanned):
                        sum_x += cur[0]
                        sum_y += cur[1]+1
                        nb_scanned += 1
                    if _try_explore(cur[0], cur[1]-1, queue, scanned):
                        sum_x += cur[0]
                        sum_y += cur[1]-1
                        nb_scanned += 1

                return round(sum_x/nb_scanned), round(sum_y/nb_scanned)

            screen_width = Screen.width(obs)
            screen_height = Screen.height(obs)
            scanned = np.zeros((screen_width, screen_height))
            self._scanned_units = []

            for x in range(screen_width):
                for y in range(screen_height):
                    if scanned[x, y] == 0 and obs.observation[SCREEN][SCREEN_UNIT_TYPE][x, y] != 0:
                        center_x, center_y = _explore_contiguous(x, y,
                                                                 obs.observation[SCREEN][SCREEN_UNIT_TYPE][x, y],
                                                                 obs.observation[SCREEN][SCREEN_PLAYER_RELATIVE][x, y],
                                                                 scanned)


                        self._scanned_units.append(Unit(Location(screen_loc=Point(center_x, center_y)),