From 355ab7d8f0522a905d77007e979d3e57734bc4e7 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 17:14:29 +0300 Subject: [PATCH 01/54] fix: [#59](https://github.com/eladyaniv01/SC2MapAnalysis/issues/59) clean air grid will now accept 'default_weight' argument (MapData, Pather) Region will not auto show a plot, following the convention of the project --- MapAnalyzer/MapData.py | 4 ++-- MapAnalyzer/Pather.py | 9 +++++++-- MapAnalyzer/Region.py | 12 +++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 64df644e..7401e808 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -94,8 +94,8 @@ def get_climber_grid(self, default_weight: int = 1) -> ndarray: def get_air_vs_ground_grid(self, default_weight: int = 100): return self.pather.get_air_vs_ground_grid(default_weight=default_weight) - def get_clean_air_grid(self): - return self.pather.get_clean_air_grid() + def get_clean_air_grid(self, default_weight: int = 1): + return self.pather.get_clean_air_grid(default_weight=default_weight) def pathfind(self, start: Tuple[int, int], goal: Tuple[int, int], grid: Optional[ndarray] = None, allow_diagonal: bool = False, sensitivity: int = 1) -> ndarray: diff --git a/MapAnalyzer/Pather.py b/MapAnalyzer/Pather.py index f02c35e7..7660105e 100644 --- a/MapAnalyzer/Pather.py +++ b/MapAnalyzer/Pather.py @@ -50,8 +50,13 @@ def get_climber_grid(self, default_weight: int = 1) -> ndarray: return grid @lru_cache() - def get_clean_air_grid(self): - return np.ones(shape=self.map_data.path_arr.shape).astype(np.float32).T + def get_clean_air_grid(self, default_weight: int = 1): + clean_air_grid = np.ones(shape=self.map_data.path_arr.shape).astype(np.float32).T + if default_weight == 1: + return clean_air_grid + else: + return np.where(clean_air_grid == 1, default_weight, 0) + @lru_cache() def get_air_vs_ground_grid(self, default_weight: int): diff --git a/MapAnalyzer/Region.py b/MapAnalyzer/Region.py index b354ad34..2e22182d 100644 --- a/MapAnalyzer/Region.py +++ b/MapAnalyzer/Region.py @@ -1,10 +1,13 @@ from functools import lru_cache -from typing import List, Union +from typing import List, TYPE_CHECKING, Union import numpy as np from sc2.position import Point2 -from . import Polygon +from MapAnalyzer.Polygon import Polygon + +if TYPE_CHECKING: + from MapAnalyzer import MapData class Region: @@ -14,7 +17,7 @@ class Region: def __init__( self, - map_data: "MapData", + map_data: 'MapData', array: np.ndarray, label: int, map_expansions: List[Point2], @@ -23,7 +26,7 @@ def __init__( self.array = array self.label = label - self.polygon = Polygon.Polygon(map_data=self.map_data, array=self.array) # for constructor + self.polygon = Polygon(map_data=self.map_data, array=self.array) # for constructor self.polygon.areas.append(self) self.polygon.is_region = True self.bases = [ @@ -63,7 +66,6 @@ def plot_perimeter(self, self_only: bool = True) -> None: plt.title(f"Region {self.label}") if self_only: # pragma: no cover plt.grid() - plt.show() def _plot_corners(self) -> None: import matplotlib.pyplot as plt From 98dcbec074e032047d4eacbb5f97e1961f06d395 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 17:31:15 +0300 Subject: [PATCH 02/54] fix: [#58](https://github.com/eladyaniv01/SC2MapAnalysis/issues/58) climber_grid is now aware of nonpathables (such as minerals, destructibles etc) moved radius types to constants for unpathables --- MapAnalyzer/Pather.py | 38 +++++++++++++++++++++----------------- MapAnalyzer/constants.py | 2 ++ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/MapAnalyzer/Pather.py b/MapAnalyzer/Pather.py index 7660105e..bbcbdf82 100644 --- a/MapAnalyzer/Pather.py +++ b/MapAnalyzer/Pather.py @@ -7,6 +7,7 @@ from sc2.position import Point2 from skimage import draw as skdraw +from MapAnalyzer.constants import NONPATHABLE_RADIUS, RESOURCE_BLOCKER_RADIUS from MapAnalyzer.exceptions import OutOfBoundsException from .sc2pathlibp import Sc2Map @@ -38,15 +39,33 @@ def _set_pathlib_map(self) -> None: self.map_data.bot.game_info.playable_area, ) + def _add_non_pathables_ground(self, grid, include_destructables: bool = True): + nonpathables = self.map_data.bot.structures + nonpathables.extend(self.map_data.bot.enemy_structures) + nonpathables.extend(self.map_data.mineral_fields) + for obj in nonpathables: + radius = NONPATHABLE_RADIUS + grid = self.add_influence(p=obj.position, r=radius * obj.radius, arr=grid, weight=np.inf) + for pos in self.map_data.resource_blockers: + radius = RESOURCE_BLOCKER_RADIUS + grid = self.add_influence(p=pos, r=radius, arr=grid, weight=np.inf) + if include_destructables: + destructables_filtered = [d for d in self.map_data.bot.destructables if "plates" not in d.name.lower()] + for rock in destructables_filtered: + if "plates" not in rock.name.lower(): + self.add_influence(p=rock.position, r=1 * rock.radius, arr=grid, weight=np.inf) + return grid + @lru_cache() def get_base_pathing_grid(self) -> ndarray: return np.fmax(self.map_data.path_arr, self.map_data.placement_arr).T @lru_cache() - def get_climber_grid(self, default_weight: int = 1) -> ndarray: + def get_climber_grid(self, default_weight: int = 1, include_destructables: bool = True) -> ndarray: """Grid for units like reaper / colossus """ grid = self._climber_grid.copy() grid = np.where(grid != 0, default_weight, np.inf).astype(np.float32) + grid = self._add_non_pathables_ground(grid=grid, include_destructables=include_destructables) return grid @lru_cache() @@ -57,7 +76,6 @@ def get_clean_air_grid(self, default_weight: int = 1): else: return np.where(clean_air_grid == 1, default_weight, 0) - @lru_cache() def get_air_vs_ground_grid(self, default_weight: int): grid = np.fmin(self.map_data.path_arr, self.map_data.placement_arr) @@ -65,23 +83,9 @@ def get_air_vs_ground_grid(self, default_weight: int): return air_vs_ground_grid.T def get_pyastar_grid(self, default_weight: int = 1, include_destructables: bool = True) -> ndarray: - grid = self.map_data.pather.get_base_pathing_grid().copy() grid = np.where(grid != 0, default_weight, np.inf).astype(np.float32) - nonpathables = self.map_data.bot.structures - nonpathables.extend(self.map_data.bot.enemy_structures) - nonpathables.extend(self.map_data.mineral_fields) - for obj in nonpathables: - radius = 0.8 - grid = self.add_influence(p=obj.position, r=radius * obj.radius, arr=grid, weight=np.inf) - for pos in self.map_data.resource_blockers: - radius = 2 - grid = self.add_influence(p=pos, r=radius, arr=grid, weight=np.inf) - if include_destructables: - destructables_filtered = [d for d in self.map_data.bot.destructables if "plates" not in d.name.lower()] - for rock in destructables_filtered: - if "plates" not in rock.name.lower(): - self.add_influence(p=rock.position, r=1 * rock.radius, arr=grid, weight=np.inf) + grid = self._add_non_pathables_ground(grid=grid, include_destructables=include_destructables) return grid def pathfind(self, start: Tuple[int, int], goal: Tuple[int, int], grid: Optional[ndarray] = None, diff --git a/MapAnalyzer/constants.py b/MapAnalyzer/constants.py index 86818910..608f5dcc 100644 --- a/MapAnalyzer/constants.py +++ b/MapAnalyzer/constants.py @@ -1,6 +1,8 @@ MIN_REGION_AREA = 25 MAX_REGION_AREA = 8500 BINARY_STRUCTURE = 2 +RESOURCE_BLOCKER_RADIUS = 2 +NONPATHABLE_RADIUS = 0.8 COLORS = { 0 : "azure", 1 : 'black', From c742d464adcc307c6e5c746a988d10f76fbf10df Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 18:11:24 +0300 Subject: [PATCH 03/54] -fix- import bugs --- MapAnalyzer/Polygon.py | 4 +--- MapAnalyzer/__init__.py | 1 - tests/test_pathihng.py | 4 ++++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/MapAnalyzer/Polygon.py b/MapAnalyzer/Polygon.py index a8fb6c29..ebf67cab 100644 --- a/MapAnalyzer/Polygon.py +++ b/MapAnalyzer/Polygon.py @@ -7,9 +7,7 @@ from scipy.ndimage import center_of_mass if TYPE_CHECKING: - from MapAnalyzer import MapData - -from MapAnalyzer.Region import Region + from MapAnalyzer import MapData, Region class Polygon: diff --git a/MapAnalyzer/__init__.py b/MapAnalyzer/__init__.py index 732c1590..c9d1e1bd 100644 --- a/MapAnalyzer/__init__.py +++ b/MapAnalyzer/__init__.py @@ -2,4 +2,3 @@ from .MapData import * from .Polygon import * from .Region import * -from .sc2pathlibp import * diff --git a/tests/test_pathihng.py b/tests/test_pathihng.py index 0f82fb7d..d31956e5 100644 --- a/tests/test_pathihng.py +++ b/tests/test_pathihng.py @@ -54,6 +54,10 @@ def test_minerals_walls() -> None: grid = map_data.get_pyastar_grid() path = map_data.pathfind(start=start, goal=goal, grid=grid) assert (path is None) + # also test climber grid for nonpathables + grid = map_data.get_climber_grid() + path = map_data.pathfind(start=start, goal=goal, grid=grid) + assert (path is None) # attempting to path through tight pathways near destructables should work path = os.path.join(get_map_files_folder(), 'AbyssalReefLE.xz') From 5216d0c8e796a3284c8e531e2ce4dcf3075582f4 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:05:32 +0300 Subject: [PATCH 04/54] fix: climber_grid tests --- tests/test_pathihng.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_pathihng.py b/tests/test_pathihng.py index d31956e5..14e89f95 100644 --- a/tests/test_pathihng.py +++ b/tests/test_pathihng.py @@ -38,7 +38,7 @@ def test_climber_grid() -> None: assert (path is None) grid = map_data.get_climber_grid() path = map_data.pathfind(start=start, goal=goal, grid=grid) - assert (path is not None) + assert (path is None) def test_minerals_walls() -> None: From 601792693b08960a96e211495607dce0dd69a943 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:11:25 +0300 Subject: [PATCH 05/54] fix: mapdata test for plotting --- tests/test_suite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_suite.py b/tests/test_suite.py index e9041ff2..23339d1f 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -29,7 +29,7 @@ def pytest_generate_tests(metafunc: Metafunc) -> None: def test_mapdata(n, m): map_files = get_map_file_list() map_data = mock_map_data(random.choice(map_files)) - map_data.save_plot() + map_data.plot_map() logger.info(f"Loaded Map : {map_data.bot.game_info.map_name}, n,m = {n}, {m}") points = [(i, j) for i in range(n + 1) for j in range(m + 1)] set_points = set(points) From 26a7c154a4a973995cea67267097aae0f9d58681 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:11:25 +0300 Subject: [PATCH 06/54] fix: mapdata test for plotting --- tests/test_suite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_suite.py b/tests/test_suite.py index e9041ff2..848304b0 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -29,7 +29,7 @@ def pytest_generate_tests(metafunc: Metafunc) -> None: def test_mapdata(n, m): map_files = get_map_file_list() map_data = mock_map_data(random.choice(map_files)) - map_data.save_plot() + # map_data.plot_map() logger.info(f"Loaded Map : {map_data.bot.game_info.map_name}, n,m = {n}, {m}") points = [(i, j) for i in range(n + 1) for j in range(m + 1)] set_points = set(points) From b8ea9126a6dea792d9d62538688c6d9d15c395d8 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:22:24 +0300 Subject: [PATCH 07/54] fix: import error on region-polygon --- MapAnalyzer/Polygon.py | 1 + 1 file changed, 1 insertion(+) diff --git a/MapAnalyzer/Polygon.py b/MapAnalyzer/Polygon.py index ebf67cab..06cb7645 100644 --- a/MapAnalyzer/Polygon.py +++ b/MapAnalyzer/Polygon.py @@ -39,6 +39,7 @@ def __init__(self, map_data: "MapData", array: ndarray) -> None: # pragma: no c @property @lru_cache() def regions(self) -> List["Region"]: + from MapAnalyzer.Region import Region if len(self.areas) > 0: return [r for r in self.areas if isinstance(r, Region)] return [] From 1694f599bcd7e925da9dd328df97310c16670926 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:35:20 +0300 Subject: [PATCH 08/54] bump setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9a16aa8a..d5b2bc51 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ ] setup( # pragma: no cover name="sc2mapanalysis", - version="0.0.48", + version="0.0.49", install_requires=requirements, setup_requires=["wheel", "numpy"], extras_require={ From a0f80537965614ac3a6dac4e13edcf1aa317c20e Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:35:28 +0300 Subject: [PATCH 09/54] chore(release): 0.0.49 --- CHANGELOG.md | 18 ++++++++++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 894e80f2..2269de83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.49](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.48...v0.0.49) (2020-08-12) + + +### Bug Fixes + +* [[#58](https://github.com/eladyaniv01/SC2MapAnalysis/issues/58)](https://github.com/eladyaniv01/SC2MapAnalysis/issues/58) climber_grid is now aware of nonpathables (such as minerals, destructibles etc) ([98dcbec](https://github.com/eladyaniv01/SC2MapAnalysis/commit/98dcbec074e032047d4eacbb5f97e1961f06d395)) +* [[#59](https://github.com/eladyaniv01/SC2MapAnalysis/issues/59)](https://github.com/eladyaniv01/SC2MapAnalysis/issues/59) clean air grid will now accept 'default_weight' argument (MapData, Pather) ([355ab7d](https://github.com/eladyaniv01/SC2MapAnalysis/commit/355ab7d8f0522a905d77007e979d3e57734bc4e7)) +* climber_grid tests ([5216d0c](https://github.com/eladyaniv01/SC2MapAnalysis/commit/5216d0c8e796a3284c8e531e2ce4dcf3075582f4)) +* import error on region-polygon ([b8ea912](https://github.com/eladyaniv01/SC2MapAnalysis/commit/b8ea9126a6dea792d9d62538688c6d9d15c395d8)) +* mapdata test for plotting ([26a7c15](https://github.com/eladyaniv01/SC2MapAnalysis/commit/26a7c154a4a973995cea67267097aae0f9d58681)) +* mapdata test for plotting ([6017926](https://github.com/eladyaniv01/SC2MapAnalysis/commit/601792693b08960a96e211495607dce0dd69a943)) +* versionbump cli now commits setup.py before calling standard-version ([50eb667](https://github.com/eladyaniv01/SC2MapAnalysis/commit/50eb667c48949a0847742ed5aec8957f07cd8ff9)) + + +### Documentation + +* added cli reminder to commit setup.py on versionbump ([28a65a3](https://github.com/eladyaniv01/SC2MapAnalysis/commit/28a65a303a14ae08bf4b00253cb2ace13b8b5cff)) + ### [0.0.48](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.47...v0.0.48) (2020-08-11) diff --git a/package-lock.json b/package-lock.json index d02cb396..4ebb586a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "Sc2MapAnalyzer", - "version": "0.0.48", + "version": "0.0.49", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ca05a575..6e8a9e12 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,4 @@ { "name": "Sc2MapAnalyzer", - "version": "0.0.48" + "version": "0.0.49" } From 64b8cebf00fa8d42ab6da071b489c1dab5e19757 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:37:09 +0300 Subject: [PATCH 10/54] clean Changelog --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2269de83..c98c89b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,6 @@ All notable changes to this project will be documented in this file. See [standa * climber_grid tests ([5216d0c](https://github.com/eladyaniv01/SC2MapAnalysis/commit/5216d0c8e796a3284c8e531e2ce4dcf3075582f4)) * import error on region-polygon ([b8ea912](https://github.com/eladyaniv01/SC2MapAnalysis/commit/b8ea9126a6dea792d9d62538688c6d9d15c395d8)) * mapdata test for plotting ([26a7c15](https://github.com/eladyaniv01/SC2MapAnalysis/commit/26a7c154a4a973995cea67267097aae0f9d58681)) -* mapdata test for plotting ([6017926](https://github.com/eladyaniv01/SC2MapAnalysis/commit/601792693b08960a96e211495607dce0dd69a943)) * versionbump cli now commits setup.py before calling standard-version ([50eb667](https://github.com/eladyaniv01/SC2MapAnalysis/commit/50eb667c48949a0847742ed5aec8957f07cd8ff9)) From 08466b5e3650a694bf5b0d633b894fdb6bfbd7b8 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 20:16:36 +0300 Subject: [PATCH 11/54] fix: [#61](https://github.com/eladyaniv01/SC2MapAnalysis/issues/61) pathfind will not crash the bot when start or goal are not passed properly, also a logging error will print out --- MapAnalyzer/Pather.py | 10 +++++++--- MapAnalyzer/exceptions.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/MapAnalyzer/Pather.py b/MapAnalyzer/Pather.py index bbcbdf82..209a5b29 100644 --- a/MapAnalyzer/Pather.py +++ b/MapAnalyzer/Pather.py @@ -8,7 +8,7 @@ from skimage import draw as skdraw from MapAnalyzer.constants import NONPATHABLE_RADIUS, RESOURCE_BLOCKER_RADIUS -from MapAnalyzer.exceptions import OutOfBoundsException +from MapAnalyzer.exceptions import OutOfBoundsException, PatherNoPointsException from .sc2pathlibp import Sc2Map if TYPE_CHECKING: @@ -90,8 +90,12 @@ def get_pyastar_grid(self, default_weight: int = 1, include_destructables: bool def pathfind(self, start: Tuple[int, int], goal: Tuple[int, int], grid: Optional[ndarray] = None, allow_diagonal: bool = False, sensitivity: int = 1) -> ndarray: - start = int(start[0]), int(start[1]) - goal = int(goal[0]), int(goal[1]) + if start is not None and goal is not None: + start = int(start[0]), int(start[1]) + goal = int(goal[0]), int(goal[1]) + else: + self.map_data.logger.error(PatherNoPointsException(start=start, goal=goal)) + return None if grid is None: grid = self.get_pyastar_grid() diff --git a/MapAnalyzer/exceptions.py b/MapAnalyzer/exceptions.py index 149de2cd..92334216 100644 --- a/MapAnalyzer/exceptions.py +++ b/MapAnalyzer/exceptions.py @@ -10,6 +10,18 @@ def __str__(self) -> str: return f"[DeprecationWarning] Passing `{self.old}` argument is deprecated, and will have no effect,\nUse `{self.new}` instead" +class PatherNoPointsException(BaseException): + def __init__(self, start, goal) -> None: + super().__init__() + self.start = start + self.goal = goal + + def __str__(self) -> str: + return f"[PatherNoPointsException]" \ + f"\nExpected: Start (pointlike), Goal (pointlike)," \ + f"\nGot: Start {self.start}, Goal {self.goal}." + + class OutOfBoundsException(BaseException): def __init__(self, p: Tuple[int, int]) -> None: super().__init__() From 7e0291dccf87e9a93877e82d02ef07b2d8e83a19 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 20:44:55 +0300 Subject: [PATCH 12/54] feat: Polygon/ Region now has the property 'buildable_points' --- MapAnalyzer/Polygon.py | 21 +++++++++++++++++++++ MapAnalyzer/Region.py | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/MapAnalyzer/Polygon.py b/MapAnalyzer/Polygon.py index 06cb7645..6ddc5252 100644 --- a/MapAnalyzer/Polygon.py +++ b/MapAnalyzer/Polygon.py @@ -10,6 +10,21 @@ from MapAnalyzer import MapData, Region +class BuildablePoints: + def __init__(self, polygon, points): + self.polygon = polygon + self.points = points + + def update(self): + parr = self.polygon.map_data.points_to_numpy_array(self.polygon.points) + buildable_indices = np.where(parr == 1) + buildable_points = [] + _points = list(self.polygon.map_data.indices_to_points(buildable_indices)) + for p in _points: + if self.polygon.map_data.placement_arr[p] == 1: + buildable_points.append(p) + self.points = buildable_points + class Polygon: """ Polygon DocString @@ -35,6 +50,12 @@ def __init__(self, map_data: "MapData", array: ndarray) -> None: # pragma: no c self.points = set([Point2(p) for p in points]) self.indices = self.map_data.points_to_indices(self.points) self.map_data.polygons.append(self) + self._buildable_points = BuildablePoints(polygon=self, points=None) + + @property + def buildable_points(self): + self._buildable_points.update() + return self._buildable_points.points @property @lru_cache() diff --git a/MapAnalyzer/Region.py b/MapAnalyzer/Region.py index 2e22182d..8b1eb5c5 100644 --- a/MapAnalyzer/Region.py +++ b/MapAnalyzer/Region.py @@ -39,6 +39,10 @@ def __init__( self.region_vb = [] self.region_chokes = [] + @property + def buildable_points(self): + return self.polygon.buildable_points + @property def center(self) -> Point2: """ From 09a872864bbec95f1a5e04890afc675627c782b6 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 00:24:38 +0300 Subject: [PATCH 13/54] feat: Polygon/ Region now has the property 'buildable_points' with some usage ideas --- MapAnalyzer/Debugger.py | 12 +++++++----- MapAnalyzer/MapData.py | 9 ++++++--- MapAnalyzer/Pather.py | 3 ++- MapAnalyzer/Polygon.py | 27 +++++++++++++++++++++------ 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/MapAnalyzer/Debugger.py b/MapAnalyzer/Debugger.py index 50969dbb..326fffaf 100644 --- a/MapAnalyzer/Debugger.py +++ b/MapAnalyzer/Debugger.py @@ -15,12 +15,14 @@ class LogFilter: - def __init__(self, level: str) -> None: - self.level = level + def __init__(self, module_name: str) -> None: + self.module_name = module_name def __call__(self, record: Dict[str, Any]) -> bool: - levelno = logger.level(self.level).no - return record["level"].no >= levelno + # return True + if self.module_name.lower() in record["name"].lower() or 'main' in record["name"].lower(): + return True + return False class MapAnalyzerDebugger: @@ -32,7 +34,7 @@ def __init__(self, map_data: "MapData", loglevel: str = "ERROR") -> None: self.warnings.filterwarnings('ignore', category=DeprecationWarning) self.warnings.filterwarnings('ignore', category=RuntimeWarning) self.logger = logger - self.log_filter = LogFilter(loglevel) + self.log_filter = LogFilter("MapAnalyzer") self.logger.remove() self.log_format = LOG_FORMAT self.logger.add(sys.stderr, format=self.log_format, filter=self.log_filter) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 7401e808..16922c2f 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -26,7 +26,6 @@ class MapData: MapData DocString """ - # todo goldenwall big region is not found def __init__(self, bot: BotAI, loglevel: str = "ERROR") -> None: # store relevant data from api self.bot = bot @@ -82,7 +81,7 @@ def vision_blockers(self) -> Set[Point2]: # dont cache this def get_pyastar_grid(self, default_weight: int = 1, include_destructables: bool = True, - air_pathing=None) -> ndarray: + air_pathing: Optional[bool] = None) -> ndarray: if air_pathing is not None: self.logger.warning(CustomDeprecationWarning(oldarg='air_pathing', newarg='self.get_clean_air_grid()')) return self.pather.get_pyastar_grid(default_weight=default_weight, include_destructables=include_destructables, @@ -202,7 +201,11 @@ def closest_towards_point( tanks in direction to the enemy forces passing in the Area's corners as points and enemy army's location as target """ - return points[self.closest_node_idx(node=target, nodes=points)] + if isinstance(points, list): + return points[self.closest_node_idx(node=target, nodes=points)] + else: + self.logger.warning(type(points)) + return points[self.closest_node_idx(node=target, nodes=points)] """Query methods""" diff --git a/MapAnalyzer/Pather.py b/MapAnalyzer/Pather.py index 209a5b29..8d7683b5 100644 --- a/MapAnalyzer/Pather.py +++ b/MapAnalyzer/Pather.py @@ -14,6 +14,7 @@ if TYPE_CHECKING: from MapAnalyzer.MapData import MapData + class MapAnalyzerPather: """""" @@ -39,7 +40,7 @@ def _set_pathlib_map(self) -> None: self.map_data.bot.game_info.playable_area, ) - def _add_non_pathables_ground(self, grid, include_destructables: bool = True): + def _add_non_pathables_ground(self, grid: ndarray, include_destructables: bool = True) -> ndarray: nonpathables = self.map_data.bot.structures nonpathables.extend(self.map_data.bot.enemy_structures) nonpathables.extend(self.map_data.mineral_fields) diff --git a/MapAnalyzer/Polygon.py b/MapAnalyzer/Polygon.py index 6ddc5252..f02781a2 100644 --- a/MapAnalyzer/Polygon.py +++ b/MapAnalyzer/Polygon.py @@ -11,20 +11,35 @@ class BuildablePoints: - def __init__(self, polygon, points): + """ChokeArea BuildablePoints are always the edges, this is useful for walling off""" + + def __init__(self, polygon): self.polygon = polygon - self.points = points + self.points = None + + @property + def free_pct(self): + if self.points is None: + self.polygon.map_data.logger.warning("BuildablePoints needs to update first") + self.update() + return len(self.points) / len(self.polygon.points) def update(self): parr = self.polygon.map_data.points_to_numpy_array(self.polygon.points) + [self.polygon.map_data.add_influence(p=(unit.position.y, unit.position.x), r=unit.radius, arr=parr, safe=False) + for unit in + self.polygon.map_data.bot.all_units] buildable_indices = np.where(parr == 1) buildable_points = [] _points = list(self.polygon.map_data.indices_to_points(buildable_indices)) + placement_grid = self.polygon.map_data.placement_arr.T for p in _points: - if self.polygon.map_data.placement_arr[p] == 1: - buildable_points.append(p) + if p[0] < placement_grid.shape[0] and p[1] < placement_grid.shape[1]: + if placement_grid[p] == 1: + buildable_points.append(p) self.points = buildable_points + class Polygon: """ Polygon DocString @@ -50,12 +65,12 @@ def __init__(self, map_data: "MapData", array: ndarray) -> None: # pragma: no c self.points = set([Point2(p) for p in points]) self.indices = self.map_data.points_to_indices(self.points) self.map_data.polygons.append(self) - self._buildable_points = BuildablePoints(polygon=self, points=None) + self._buildable_points = BuildablePoints(polygon=self) @property def buildable_points(self): self._buildable_points.update() - return self._buildable_points.points + return self._buildable_points @property @lru_cache() From 9d9477aba9068098c5f39284ee962385216cf7d1 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:11:03 +0300 Subject: [PATCH 14/54] feat: Polygon/ Region now has the property 'buildable_points' with some usage ideas --- .github/workflows/build_on_setup.yml | 2 +- MapAnalyzer/MapData.py | 2 +- tests/test_suite.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_on_setup.yml b/.github/workflows/build_on_setup.yml index 281ccc64..7f56d1fb 100644 --- a/.github/workflows/build_on_setup.yml +++ b/.github/workflows/build_on_setup.yml @@ -2,7 +2,7 @@ name: BuildOnSetup on: push: - branches: [ master ] + branches: [ master, dev ] pull_request: branches: [ master, dev ] diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 16922c2f..5a5e92a4 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - rows, cols = self.path_arr.shape + cols, rows = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) indices = self.points_to_indices(points) arr[indices] = 1 diff --git a/tests/test_suite.py b/tests/test_suite.py index 848304b0..56d26247 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -67,6 +67,7 @@ def test_polygon(self, map_data: MapData) -> None: for point in polygon.corner_points: assert (point in polygon.corner_array) + assert (polygon.buildable_points.free_pct is not None) def test_regions(self, map_data: MapData) -> None: for region in map_data.regions.values(): From 18c464274dee7549bea10352736225f9917bd3c5 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:31:27 +0300 Subject: [PATCH 15/54] fix: fix point_to_numpy_array method --- MapAnalyzer/MapData.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 5a5e92a4..16922c2f 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - cols, rows = self.path_arr.shape + rows, cols = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) indices = self.points_to_indices(points) arr[indices] = 1 From dae199bfed3ce509cc4148864508e3a687718455 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:35:15 +0300 Subject: [PATCH 16/54] fix: update according to last fix --- MapAnalyzer/Polygon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/Polygon.py b/MapAnalyzer/Polygon.py index f02781a2..07731852 100644 --- a/MapAnalyzer/Polygon.py +++ b/MapAnalyzer/Polygon.py @@ -26,7 +26,7 @@ def free_pct(self): def update(self): parr = self.polygon.map_data.points_to_numpy_array(self.polygon.points) - [self.polygon.map_data.add_influence(p=(unit.position.y, unit.position.x), r=unit.radius, arr=parr, safe=False) + [self.polygon.map_data.add_influence(p=(unit.position.x, unit.position.y), r=unit.radius, arr=parr, safe=False) for unit in self.polygon.map_data.bot.all_units] buildable_indices = np.where(parr == 1) From f15a360e7a861dc911a3cc08649be1c9b9e4da13 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 03:31:36 +0300 Subject: [PATCH 17/54] fix: points_to_numpy_array now filters out outofbounds --- MapAnalyzer/MapData.py | 21 ++++++++++++++++++++- MapAnalyzer/Pather.py | 2 +- MapAnalyzer/constants.py | 10 +++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 16922c2f..8a319f3b 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -169,8 +169,27 @@ def points_to_numpy_array( """ rows, cols = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) + if isinstance(points, set): + points = list(points) + + def in_bounds_x(x): + width = arr.shape[0] - 1 + if 0 < x < width: + return x + return 0 + + def in_bounds_y(y): + height = arr.shape[1] - 1 + if 0 < y < height: + return y + return 0 + + x_vec = np.vectorize(in_bounds_x) + y_vec = np.vectorize(in_bounds_y) indices = self.points_to_indices(points) - arr[indices] = 1 + x = x_vec(indices[0]) + y = y_vec(indices[1]) + arr[x, y] = 1 return arr @staticmethod diff --git a/MapAnalyzer/Pather.py b/MapAnalyzer/Pather.py index 8d7683b5..66ae7367 100644 --- a/MapAnalyzer/Pather.py +++ b/MapAnalyzer/Pather.py @@ -95,7 +95,7 @@ def pathfind(self, start: Tuple[int, int], goal: Tuple[int, int], grid: Optional start = int(start[0]), int(start[1]) goal = int(goal[0]), int(goal[1]) else: - self.map_data.logger.error(PatherNoPointsException(start=start, goal=goal)) + self.map_data.logger.warning(PatherNoPointsException(start=start, goal=goal)) return None if grid is None: grid = self.get_pyastar_grid() diff --git a/MapAnalyzer/constants.py b/MapAnalyzer/constants.py index 608f5dcc..d3d60e74 100644 --- a/MapAnalyzer/constants.py +++ b/MapAnalyzer/constants.py @@ -26,8 +26,8 @@ 19: "azure", 20: "azure" } -LOG_FORMAT = "{time:YY:MM:DD:HH:mm:ss} |" \ - " {level: <8} | {name: ^15} |" \ - " {function: ^15} |" \ - " {line: >4} |" \ - " {level.icon} {message}" +LOG_FORMAT = "{time:YY:MM:DD:HH:mm:ss}|" \ + "{level: <8}|{name: ^15}|" \ + "{function: ^15}|" \ + "{line: >4}|" \ + "{level.icon}{message}" From 3d359b183806fcb15b67ed64ad816e617278ec19 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:11:25 +0300 Subject: [PATCH 18/54] fix: mapdata test for plotting --- tests/test_suite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_suite.py b/tests/test_suite.py index 848304b0..23339d1f 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -29,7 +29,7 @@ def pytest_generate_tests(metafunc: Metafunc) -> None: def test_mapdata(n, m): map_files = get_map_file_list() map_data = mock_map_data(random.choice(map_files)) - # map_data.plot_map() + map_data.plot_map() logger.info(f"Loaded Map : {map_data.bot.game_info.map_name}, n,m = {n}, {m}") points = [(i, j) for i in range(n + 1) for j in range(m + 1)] set_points = set(points) From 0ce534b46839f1b983d5512ebcbbad9644cc37cf Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:11:25 +0300 Subject: [PATCH 19/54] fix: mapdata test for plotting --- tests/test_suite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_suite.py b/tests/test_suite.py index 23339d1f..848304b0 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -29,7 +29,7 @@ def pytest_generate_tests(metafunc: Metafunc) -> None: def test_mapdata(n, m): map_files = get_map_file_list() map_data = mock_map_data(random.choice(map_files)) - map_data.plot_map() + # map_data.plot_map() logger.info(f"Loaded Map : {map_data.bot.game_info.map_name}, n,m = {n}, {m}") points = [(i, j) for i in range(n + 1) for j in range(m + 1)] set_points = set(points) From 96dde12493f1f285c72a1e1f335714db442930ff Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:35:28 +0300 Subject: [PATCH 20/54] chore(release): 0.0.49 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c98c89b6..2269de83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. See [standa * climber_grid tests ([5216d0c](https://github.com/eladyaniv01/SC2MapAnalysis/commit/5216d0c8e796a3284c8e531e2ce4dcf3075582f4)) * import error on region-polygon ([b8ea912](https://github.com/eladyaniv01/SC2MapAnalysis/commit/b8ea9126a6dea792d9d62538688c6d9d15c395d8)) * mapdata test for plotting ([26a7c15](https://github.com/eladyaniv01/SC2MapAnalysis/commit/26a7c154a4a973995cea67267097aae0f9d58681)) +* mapdata test for plotting ([6017926](https://github.com/eladyaniv01/SC2MapAnalysis/commit/601792693b08960a96e211495607dce0dd69a943)) * versionbump cli now commits setup.py before calling standard-version ([50eb667](https://github.com/eladyaniv01/SC2MapAnalysis/commit/50eb667c48949a0847742ed5aec8957f07cd8ff9)) From f5ba08447a8a05be2454234046d415d28149c13e Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:37:09 +0300 Subject: [PATCH 21/54] clean Changelog --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2269de83..c98c89b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,6 @@ All notable changes to this project will be documented in this file. See [standa * climber_grid tests ([5216d0c](https://github.com/eladyaniv01/SC2MapAnalysis/commit/5216d0c8e796a3284c8e531e2ce4dcf3075582f4)) * import error on region-polygon ([b8ea912](https://github.com/eladyaniv01/SC2MapAnalysis/commit/b8ea9126a6dea792d9d62538688c6d9d15c395d8)) * mapdata test for plotting ([26a7c15](https://github.com/eladyaniv01/SC2MapAnalysis/commit/26a7c154a4a973995cea67267097aae0f9d58681)) -* mapdata test for plotting ([6017926](https://github.com/eladyaniv01/SC2MapAnalysis/commit/601792693b08960a96e211495607dce0dd69a943)) * versionbump cli now commits setup.py before calling standard-version ([50eb667](https://github.com/eladyaniv01/SC2MapAnalysis/commit/50eb667c48949a0847742ed5aec8957f07cd8ff9)) From 25952f75ed05a762124ae97e8425c946dd4cf058 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 20:44:55 +0300 Subject: [PATCH 22/54] feat: Polygon/ Region now has the property 'buildable_points' --- MapAnalyzer/Polygon.py | 21 +++++++++++++++++++++ MapAnalyzer/Region.py | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/MapAnalyzer/Polygon.py b/MapAnalyzer/Polygon.py index 06cb7645..6ddc5252 100644 --- a/MapAnalyzer/Polygon.py +++ b/MapAnalyzer/Polygon.py @@ -10,6 +10,21 @@ from MapAnalyzer import MapData, Region +class BuildablePoints: + def __init__(self, polygon, points): + self.polygon = polygon + self.points = points + + def update(self): + parr = self.polygon.map_data.points_to_numpy_array(self.polygon.points) + buildable_indices = np.where(parr == 1) + buildable_points = [] + _points = list(self.polygon.map_data.indices_to_points(buildable_indices)) + for p in _points: + if self.polygon.map_data.placement_arr[p] == 1: + buildable_points.append(p) + self.points = buildable_points + class Polygon: """ Polygon DocString @@ -35,6 +50,12 @@ def __init__(self, map_data: "MapData", array: ndarray) -> None: # pragma: no c self.points = set([Point2(p) for p in points]) self.indices = self.map_data.points_to_indices(self.points) self.map_data.polygons.append(self) + self._buildable_points = BuildablePoints(polygon=self, points=None) + + @property + def buildable_points(self): + self._buildable_points.update() + return self._buildable_points.points @property @lru_cache() diff --git a/MapAnalyzer/Region.py b/MapAnalyzer/Region.py index 2e22182d..8b1eb5c5 100644 --- a/MapAnalyzer/Region.py +++ b/MapAnalyzer/Region.py @@ -39,6 +39,10 @@ def __init__( self.region_vb = [] self.region_chokes = [] + @property + def buildable_points(self): + return self.polygon.buildable_points + @property def center(self) -> Point2: """ From 9a3408a6df4f6d5ce326488db24f95df1aedc3d2 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 00:24:38 +0300 Subject: [PATCH 23/54] feat: Polygon/ Region now has the property 'buildable_points' with some usage ideas --- MapAnalyzer/Debugger.py | 12 +++++++----- MapAnalyzer/MapData.py | 9 ++++++--- MapAnalyzer/Pather.py | 3 ++- MapAnalyzer/Polygon.py | 27 +++++++++++++++++++++------ 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/MapAnalyzer/Debugger.py b/MapAnalyzer/Debugger.py index 50969dbb..326fffaf 100644 --- a/MapAnalyzer/Debugger.py +++ b/MapAnalyzer/Debugger.py @@ -15,12 +15,14 @@ class LogFilter: - def __init__(self, level: str) -> None: - self.level = level + def __init__(self, module_name: str) -> None: + self.module_name = module_name def __call__(self, record: Dict[str, Any]) -> bool: - levelno = logger.level(self.level).no - return record["level"].no >= levelno + # return True + if self.module_name.lower() in record["name"].lower() or 'main' in record["name"].lower(): + return True + return False class MapAnalyzerDebugger: @@ -32,7 +34,7 @@ def __init__(self, map_data: "MapData", loglevel: str = "ERROR") -> None: self.warnings.filterwarnings('ignore', category=DeprecationWarning) self.warnings.filterwarnings('ignore', category=RuntimeWarning) self.logger = logger - self.log_filter = LogFilter(loglevel) + self.log_filter = LogFilter("MapAnalyzer") self.logger.remove() self.log_format = LOG_FORMAT self.logger.add(sys.stderr, format=self.log_format, filter=self.log_filter) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 7401e808..16922c2f 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -26,7 +26,6 @@ class MapData: MapData DocString """ - # todo goldenwall big region is not found def __init__(self, bot: BotAI, loglevel: str = "ERROR") -> None: # store relevant data from api self.bot = bot @@ -82,7 +81,7 @@ def vision_blockers(self) -> Set[Point2]: # dont cache this def get_pyastar_grid(self, default_weight: int = 1, include_destructables: bool = True, - air_pathing=None) -> ndarray: + air_pathing: Optional[bool] = None) -> ndarray: if air_pathing is not None: self.logger.warning(CustomDeprecationWarning(oldarg='air_pathing', newarg='self.get_clean_air_grid()')) return self.pather.get_pyastar_grid(default_weight=default_weight, include_destructables=include_destructables, @@ -202,7 +201,11 @@ def closest_towards_point( tanks in direction to the enemy forces passing in the Area's corners as points and enemy army's location as target """ - return points[self.closest_node_idx(node=target, nodes=points)] + if isinstance(points, list): + return points[self.closest_node_idx(node=target, nodes=points)] + else: + self.logger.warning(type(points)) + return points[self.closest_node_idx(node=target, nodes=points)] """Query methods""" diff --git a/MapAnalyzer/Pather.py b/MapAnalyzer/Pather.py index 209a5b29..8d7683b5 100644 --- a/MapAnalyzer/Pather.py +++ b/MapAnalyzer/Pather.py @@ -14,6 +14,7 @@ if TYPE_CHECKING: from MapAnalyzer.MapData import MapData + class MapAnalyzerPather: """""" @@ -39,7 +40,7 @@ def _set_pathlib_map(self) -> None: self.map_data.bot.game_info.playable_area, ) - def _add_non_pathables_ground(self, grid, include_destructables: bool = True): + def _add_non_pathables_ground(self, grid: ndarray, include_destructables: bool = True) -> ndarray: nonpathables = self.map_data.bot.structures nonpathables.extend(self.map_data.bot.enemy_structures) nonpathables.extend(self.map_data.mineral_fields) diff --git a/MapAnalyzer/Polygon.py b/MapAnalyzer/Polygon.py index 6ddc5252..f02781a2 100644 --- a/MapAnalyzer/Polygon.py +++ b/MapAnalyzer/Polygon.py @@ -11,20 +11,35 @@ class BuildablePoints: - def __init__(self, polygon, points): + """ChokeArea BuildablePoints are always the edges, this is useful for walling off""" + + def __init__(self, polygon): self.polygon = polygon - self.points = points + self.points = None + + @property + def free_pct(self): + if self.points is None: + self.polygon.map_data.logger.warning("BuildablePoints needs to update first") + self.update() + return len(self.points) / len(self.polygon.points) def update(self): parr = self.polygon.map_data.points_to_numpy_array(self.polygon.points) + [self.polygon.map_data.add_influence(p=(unit.position.y, unit.position.x), r=unit.radius, arr=parr, safe=False) + for unit in + self.polygon.map_data.bot.all_units] buildable_indices = np.where(parr == 1) buildable_points = [] _points = list(self.polygon.map_data.indices_to_points(buildable_indices)) + placement_grid = self.polygon.map_data.placement_arr.T for p in _points: - if self.polygon.map_data.placement_arr[p] == 1: - buildable_points.append(p) + if p[0] < placement_grid.shape[0] and p[1] < placement_grid.shape[1]: + if placement_grid[p] == 1: + buildable_points.append(p) self.points = buildable_points + class Polygon: """ Polygon DocString @@ -50,12 +65,12 @@ def __init__(self, map_data: "MapData", array: ndarray) -> None: # pragma: no c self.points = set([Point2(p) for p in points]) self.indices = self.map_data.points_to_indices(self.points) self.map_data.polygons.append(self) - self._buildable_points = BuildablePoints(polygon=self, points=None) + self._buildable_points = BuildablePoints(polygon=self) @property def buildable_points(self): self._buildable_points.update() - return self._buildable_points.points + return self._buildable_points @property @lru_cache() From 41282a150595bace594d16f2d2f51d24b9372dc9 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:11:03 +0300 Subject: [PATCH 24/54] feat: Polygon/ Region now has the property 'buildable_points' with some usage ideas --- .github/workflows/build_on_setup.yml | 2 +- MapAnalyzer/MapData.py | 2 +- tests/test_suite.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_on_setup.yml b/.github/workflows/build_on_setup.yml index 281ccc64..7f56d1fb 100644 --- a/.github/workflows/build_on_setup.yml +++ b/.github/workflows/build_on_setup.yml @@ -2,7 +2,7 @@ name: BuildOnSetup on: push: - branches: [ master ] + branches: [ master, dev ] pull_request: branches: [ master, dev ] diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 16922c2f..5a5e92a4 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - rows, cols = self.path_arr.shape + cols, rows = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) indices = self.points_to_indices(points) arr[indices] = 1 diff --git a/tests/test_suite.py b/tests/test_suite.py index 848304b0..56d26247 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -67,6 +67,7 @@ def test_polygon(self, map_data: MapData) -> None: for point in polygon.corner_points: assert (point in polygon.corner_array) + assert (polygon.buildable_points.free_pct is not None) def test_regions(self, map_data: MapData) -> None: for region in map_data.regions.values(): From 24af6b8c0d9d326235bc4c748887fcb6bf884b45 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:31:27 +0300 Subject: [PATCH 25/54] fix: fix point_to_numpy_array method --- MapAnalyzer/MapData.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 5a5e92a4..16922c2f 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - cols, rows = self.path_arr.shape + rows, cols = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) indices = self.points_to_indices(points) arr[indices] = 1 From 486f0f9346cec936228492aba77e5e7ced22a259 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:35:15 +0300 Subject: [PATCH 26/54] fix: update according to last fix --- MapAnalyzer/Polygon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/Polygon.py b/MapAnalyzer/Polygon.py index f02781a2..07731852 100644 --- a/MapAnalyzer/Polygon.py +++ b/MapAnalyzer/Polygon.py @@ -26,7 +26,7 @@ def free_pct(self): def update(self): parr = self.polygon.map_data.points_to_numpy_array(self.polygon.points) - [self.polygon.map_data.add_influence(p=(unit.position.y, unit.position.x), r=unit.radius, arr=parr, safe=False) + [self.polygon.map_data.add_influence(p=(unit.position.x, unit.position.y), r=unit.radius, arr=parr, safe=False) for unit in self.polygon.map_data.bot.all_units] buildable_indices = np.where(parr == 1) From aedf9d2ba45f585a279d7a014a7e990cbb9359a9 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 03:31:36 +0300 Subject: [PATCH 27/54] fix: points_to_numpy_array now filters out outofbounds --- MapAnalyzer/MapData.py | 21 ++++++++++++++++++++- MapAnalyzer/Pather.py | 2 +- MapAnalyzer/constants.py | 10 +++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 16922c2f..8a319f3b 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -169,8 +169,27 @@ def points_to_numpy_array( """ rows, cols = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) + if isinstance(points, set): + points = list(points) + + def in_bounds_x(x): + width = arr.shape[0] - 1 + if 0 < x < width: + return x + return 0 + + def in_bounds_y(y): + height = arr.shape[1] - 1 + if 0 < y < height: + return y + return 0 + + x_vec = np.vectorize(in_bounds_x) + y_vec = np.vectorize(in_bounds_y) indices = self.points_to_indices(points) - arr[indices] = 1 + x = x_vec(indices[0]) + y = y_vec(indices[1]) + arr[x, y] = 1 return arr @staticmethod diff --git a/MapAnalyzer/Pather.py b/MapAnalyzer/Pather.py index 8d7683b5..66ae7367 100644 --- a/MapAnalyzer/Pather.py +++ b/MapAnalyzer/Pather.py @@ -95,7 +95,7 @@ def pathfind(self, start: Tuple[int, int], goal: Tuple[int, int], grid: Optional start = int(start[0]), int(start[1]) goal = int(goal[0]), int(goal[1]) else: - self.map_data.logger.error(PatherNoPointsException(start=start, goal=goal)) + self.map_data.logger.warning(PatherNoPointsException(start=start, goal=goal)) return None if grid is None: grid = self.get_pyastar_grid() diff --git a/MapAnalyzer/constants.py b/MapAnalyzer/constants.py index 608f5dcc..d3d60e74 100644 --- a/MapAnalyzer/constants.py +++ b/MapAnalyzer/constants.py @@ -26,8 +26,8 @@ 19: "azure", 20: "azure" } -LOG_FORMAT = "{time:YY:MM:DD:HH:mm:ss} |" \ - " {level: <8} | {name: ^15} |" \ - " {function: ^15} |" \ - " {line: >4} |" \ - " {level.icon} {message}" +LOG_FORMAT = "{time:YY:MM:DD:HH:mm:ss}|" \ + "{level: <8}|{name: ^15}|" \ + "{function: ^15}|" \ + "{line: >4}|" \ + "{level.icon}{message}" From 54e84f0f4e96f8962540f27d86cfae3cc30a0378 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:11:03 +0300 Subject: [PATCH 28/54] feat: Polygon/ Region now has the property 'buildable_points' with some usage ideas --- MapAnalyzer/MapData.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 8a319f3b..7866e3a5 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - rows, cols = self.path_arr.shape + cols, rows = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) if isinstance(points, set): points = list(points) From 4d567559e3eceede00615c637458cdb8a0870d36 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:31:27 +0300 Subject: [PATCH 29/54] fix: fix point_to_numpy_array method --- MapAnalyzer/MapData.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 7866e3a5..8a319f3b 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - cols, rows = self.path_arr.shape + rows, cols = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) if isinstance(points, set): points = list(points) From b7e185a1ab4c2e7e52c8a8a17f78e62cc4383c1c Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 18:13:24 +0300 Subject: [PATCH 30/54] bump setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d5b2bc51..d8a0056f 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ ] setup( # pragma: no cover name="sc2mapanalysis", - version="0.0.49", + version="0.0.50", install_requires=requirements, setup_requires=["wheel", "numpy"], extras_require={ From 21f3ec5228a7a9866e71dfbddf3e4579709532b7 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 18:13:30 +0300 Subject: [PATCH 31/54] chore(release): 0.0.50 --- CHANGELOG.md | 27 +++++++++++++++++++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c98c89b6..e12d1ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,33 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.50](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.49...v0.0.50) (2020-08-13) + + +### Features + +* Polygon/ Region now has the property 'buildable_points' ([25952f7](https://github.com/eladyaniv01/SC2MapAnalysis/commit/25952f75ed05a762124ae97e8425c946dd4cf058)) +* Polygon/ Region now has the property 'buildable_points' ([7e0291d](https://github.com/eladyaniv01/SC2MapAnalysis/commit/7e0291dccf87e9a93877e82d02ef07b2d8e83a19)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([54e84f0](https://github.com/eladyaniv01/SC2MapAnalysis/commit/54e84f0f4e96f8962540f27d86cfae3cc30a0378)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([41282a1](https://github.com/eladyaniv01/SC2MapAnalysis/commit/41282a150595bace594d16f2d2f51d24b9372dc9)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([9a3408a](https://github.com/eladyaniv01/SC2MapAnalysis/commit/9a3408a6df4f6d5ce326488db24f95df1aedc3d2)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([9d9477a](https://github.com/eladyaniv01/SC2MapAnalysis/commit/9d9477aba9068098c5f39284ee962385216cf7d1)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([09a8728](https://github.com/eladyaniv01/SC2MapAnalysis/commit/09a872864bbec95f1a5e04890afc675627c782b6)) + + +### Bug Fixes + +* [[#61](https://github.com/eladyaniv01/SC2MapAnalysis/issues/61)](https://github.com/eladyaniv01/SC2MapAnalysis/issues/61) pathfind will not crash the bot when start or goal are not passed properly, also a logging error will print out ([08466b5](https://github.com/eladyaniv01/SC2MapAnalysis/commit/08466b5e3650a694bf5b0d633b894fdb6bfbd7b8)) +* fix point_to_numpy_array method ([4d56755](https://github.com/eladyaniv01/SC2MapAnalysis/commit/4d567559e3eceede00615c637458cdb8a0870d36)) +* fix point_to_numpy_array method ([24af6b8](https://github.com/eladyaniv01/SC2MapAnalysis/commit/24af6b8c0d9d326235bc4c748887fcb6bf884b45)) +* fix point_to_numpy_array method ([18c4642](https://github.com/eladyaniv01/SC2MapAnalysis/commit/18c464274dee7549bea10352736225f9917bd3c5)) +* mapdata test for plotting ([0ce534b](https://github.com/eladyaniv01/SC2MapAnalysis/commit/0ce534b46839f1b983d5512ebcbbad9644cc37cf)) +* mapdata test for plotting ([3d359b1](https://github.com/eladyaniv01/SC2MapAnalysis/commit/3d359b183806fcb15b67ed64ad816e617278ec19)) +* points_to_numpy_array now filters out outofbounds ([aedf9d2](https://github.com/eladyaniv01/SC2MapAnalysis/commit/aedf9d2ba45f585a279d7a014a7e990cbb9359a9)) +* points_to_numpy_array now filters out outofbounds ([f15a360](https://github.com/eladyaniv01/SC2MapAnalysis/commit/f15a360e7a861dc911a3cc08649be1c9b9e4da13)) +* update according to last fix ([486f0f9](https://github.com/eladyaniv01/SC2MapAnalysis/commit/486f0f9346cec936228492aba77e5e7ced22a259)) +* update according to last fix ([dae199b](https://github.com/eladyaniv01/SC2MapAnalysis/commit/dae199bfed3ce509cc4148864508e3a687718455)) + ### [0.0.49](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.48...v0.0.49) (2020-08-12) diff --git a/package-lock.json b/package-lock.json index 4ebb586a..3c1dd8fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "Sc2MapAnalyzer", - "version": "0.0.49", + "version": "0.0.50", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6e8a9e12..6dd0ab63 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,4 @@ { "name": "Sc2MapAnalyzer", - "version": "0.0.49" + "version": "0.0.50" } From 0ac85318887466af14cd8bbf03a5676b7e0b648b Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 18:16:28 +0300 Subject: [PATCH 32/54] rebase master to catch ahead commit in --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d8a0056f..0089cf68 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ ] setup( # pragma: no cover - name="sc2mapanalysis", + name="sc2mapanalyzer", version="0.0.50", install_requires=requirements, setup_requires=["wheel", "numpy"], From 0af2c8fbcf503daf1c0f73a3b0d508c7700c9112 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 18:17:05 +0300 Subject: [PATCH 33/54] bump setup.py --- CHANGELOG.md | 27 --------------------------- package-lock.json | 2 +- package.json | 4 ++-- 3 files changed, 3 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e12d1ffd..c98c89b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,33 +2,6 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. -### [0.0.50](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.49...v0.0.50) (2020-08-13) - - -### Features - -* Polygon/ Region now has the property 'buildable_points' ([25952f7](https://github.com/eladyaniv01/SC2MapAnalysis/commit/25952f75ed05a762124ae97e8425c946dd4cf058)) -* Polygon/ Region now has the property 'buildable_points' ([7e0291d](https://github.com/eladyaniv01/SC2MapAnalysis/commit/7e0291dccf87e9a93877e82d02ef07b2d8e83a19)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([54e84f0](https://github.com/eladyaniv01/SC2MapAnalysis/commit/54e84f0f4e96f8962540f27d86cfae3cc30a0378)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([41282a1](https://github.com/eladyaniv01/SC2MapAnalysis/commit/41282a150595bace594d16f2d2f51d24b9372dc9)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([9a3408a](https://github.com/eladyaniv01/SC2MapAnalysis/commit/9a3408a6df4f6d5ce326488db24f95df1aedc3d2)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([9d9477a](https://github.com/eladyaniv01/SC2MapAnalysis/commit/9d9477aba9068098c5f39284ee962385216cf7d1)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([09a8728](https://github.com/eladyaniv01/SC2MapAnalysis/commit/09a872864bbec95f1a5e04890afc675627c782b6)) - - -### Bug Fixes - -* [[#61](https://github.com/eladyaniv01/SC2MapAnalysis/issues/61)](https://github.com/eladyaniv01/SC2MapAnalysis/issues/61) pathfind will not crash the bot when start or goal are not passed properly, also a logging error will print out ([08466b5](https://github.com/eladyaniv01/SC2MapAnalysis/commit/08466b5e3650a694bf5b0d633b894fdb6bfbd7b8)) -* fix point_to_numpy_array method ([4d56755](https://github.com/eladyaniv01/SC2MapAnalysis/commit/4d567559e3eceede00615c637458cdb8a0870d36)) -* fix point_to_numpy_array method ([24af6b8](https://github.com/eladyaniv01/SC2MapAnalysis/commit/24af6b8c0d9d326235bc4c748887fcb6bf884b45)) -* fix point_to_numpy_array method ([18c4642](https://github.com/eladyaniv01/SC2MapAnalysis/commit/18c464274dee7549bea10352736225f9917bd3c5)) -* mapdata test for plotting ([0ce534b](https://github.com/eladyaniv01/SC2MapAnalysis/commit/0ce534b46839f1b983d5512ebcbbad9644cc37cf)) -* mapdata test for plotting ([3d359b1](https://github.com/eladyaniv01/SC2MapAnalysis/commit/3d359b183806fcb15b67ed64ad816e617278ec19)) -* points_to_numpy_array now filters out outofbounds ([aedf9d2](https://github.com/eladyaniv01/SC2MapAnalysis/commit/aedf9d2ba45f585a279d7a014a7e990cbb9359a9)) -* points_to_numpy_array now filters out outofbounds ([f15a360](https://github.com/eladyaniv01/SC2MapAnalysis/commit/f15a360e7a861dc911a3cc08649be1c9b9e4da13)) -* update according to last fix ([486f0f9](https://github.com/eladyaniv01/SC2MapAnalysis/commit/486f0f9346cec936228492aba77e5e7ced22a259)) -* update according to last fix ([dae199b](https://github.com/eladyaniv01/SC2MapAnalysis/commit/dae199bfed3ce509cc4148864508e3a687718455)) - ### [0.0.49](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.48...v0.0.49) (2020-08-12) diff --git a/package-lock.json b/package-lock.json index 3c1dd8fa..4ebb586a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "Sc2MapAnalyzer", - "version": "0.0.50", + "version": "0.0.49", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6dd0ab63..744d135e 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,4 @@ { - "name": "Sc2MapAnalyzer", - "version": "0.0.50" + "name": "sc2mapanalyzer", + "version": "0.0.49" } From 73762c0a27f1ec352582f3d0087bd9bbf81316e0 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 18:17:06 +0300 Subject: [PATCH 34/54] chore(release): 0.0.50 --- CHANGELOG.md | 27 +++++++++++++++++++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c98c89b6..e12d1ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,33 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.50](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.49...v0.0.50) (2020-08-13) + + +### Features + +* Polygon/ Region now has the property 'buildable_points' ([25952f7](https://github.com/eladyaniv01/SC2MapAnalysis/commit/25952f75ed05a762124ae97e8425c946dd4cf058)) +* Polygon/ Region now has the property 'buildable_points' ([7e0291d](https://github.com/eladyaniv01/SC2MapAnalysis/commit/7e0291dccf87e9a93877e82d02ef07b2d8e83a19)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([54e84f0](https://github.com/eladyaniv01/SC2MapAnalysis/commit/54e84f0f4e96f8962540f27d86cfae3cc30a0378)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([41282a1](https://github.com/eladyaniv01/SC2MapAnalysis/commit/41282a150595bace594d16f2d2f51d24b9372dc9)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([9a3408a](https://github.com/eladyaniv01/SC2MapAnalysis/commit/9a3408a6df4f6d5ce326488db24f95df1aedc3d2)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([9d9477a](https://github.com/eladyaniv01/SC2MapAnalysis/commit/9d9477aba9068098c5f39284ee962385216cf7d1)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([09a8728](https://github.com/eladyaniv01/SC2MapAnalysis/commit/09a872864bbec95f1a5e04890afc675627c782b6)) + + +### Bug Fixes + +* [[#61](https://github.com/eladyaniv01/SC2MapAnalysis/issues/61)](https://github.com/eladyaniv01/SC2MapAnalysis/issues/61) pathfind will not crash the bot when start or goal are not passed properly, also a logging error will print out ([08466b5](https://github.com/eladyaniv01/SC2MapAnalysis/commit/08466b5e3650a694bf5b0d633b894fdb6bfbd7b8)) +* fix point_to_numpy_array method ([4d56755](https://github.com/eladyaniv01/SC2MapAnalysis/commit/4d567559e3eceede00615c637458cdb8a0870d36)) +* fix point_to_numpy_array method ([24af6b8](https://github.com/eladyaniv01/SC2MapAnalysis/commit/24af6b8c0d9d326235bc4c748887fcb6bf884b45)) +* fix point_to_numpy_array method ([18c4642](https://github.com/eladyaniv01/SC2MapAnalysis/commit/18c464274dee7549bea10352736225f9917bd3c5)) +* mapdata test for plotting ([0ce534b](https://github.com/eladyaniv01/SC2MapAnalysis/commit/0ce534b46839f1b983d5512ebcbbad9644cc37cf)) +* mapdata test for plotting ([3d359b1](https://github.com/eladyaniv01/SC2MapAnalysis/commit/3d359b183806fcb15b67ed64ad816e617278ec19)) +* points_to_numpy_array now filters out outofbounds ([aedf9d2](https://github.com/eladyaniv01/SC2MapAnalysis/commit/aedf9d2ba45f585a279d7a014a7e990cbb9359a9)) +* points_to_numpy_array now filters out outofbounds ([f15a360](https://github.com/eladyaniv01/SC2MapAnalysis/commit/f15a360e7a861dc911a3cc08649be1c9b9e4da13)) +* update according to last fix ([486f0f9](https://github.com/eladyaniv01/SC2MapAnalysis/commit/486f0f9346cec936228492aba77e5e7ced22a259)) +* update according to last fix ([dae199b](https://github.com/eladyaniv01/SC2MapAnalysis/commit/dae199bfed3ce509cc4148864508e3a687718455)) + ### [0.0.49](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.48...v0.0.49) (2020-08-12) diff --git a/package-lock.json b/package-lock.json index 4ebb586a..3c1dd8fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "Sc2MapAnalyzer", - "version": "0.0.49", + "version": "0.0.50", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 744d135e..f2551307 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,4 @@ { "name": "sc2mapanalyzer", - "version": "0.0.49" + "version": "0.0.50" } From 1e3d3f03bdf75d48456639fbfd64316b3872af21 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 18:20:01 +0300 Subject: [PATCH 35/54] chore: version bump --- CHANGELOG.md | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e12d1ffd..748201b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,34 +8,22 @@ All notable changes to this project will be documented in this file. See [standa ### Features * Polygon/ Region now has the property 'buildable_points' ([25952f7](https://github.com/eladyaniv01/SC2MapAnalysis/commit/25952f75ed05a762124ae97e8425c946dd4cf058)) -* Polygon/ Region now has the property 'buildable_points' ([7e0291d](https://github.com/eladyaniv01/SC2MapAnalysis/commit/7e0291dccf87e9a93877e82d02ef07b2d8e83a19)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([54e84f0](https://github.com/eladyaniv01/SC2MapAnalysis/commit/54e84f0f4e96f8962540f27d86cfae3cc30a0378)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([41282a1](https://github.com/eladyaniv01/SC2MapAnalysis/commit/41282a150595bace594d16f2d2f51d24b9372dc9)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([9a3408a](https://github.com/eladyaniv01/SC2MapAnalysis/commit/9a3408a6df4f6d5ce326488db24f95df1aedc3d2)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([9d9477a](https://github.com/eladyaniv01/SC2MapAnalysis/commit/9d9477aba9068098c5f39284ee962385216cf7d1)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([09a8728](https://github.com/eladyaniv01/SC2MapAnalysis/commit/09a872864bbec95f1a5e04890afc675627c782b6)) ### Bug Fixes -* [[#61](https://github.com/eladyaniv01/SC2MapAnalysis/issues/61)](https://github.com/eladyaniv01/SC2MapAnalysis/issues/61) pathfind will not crash the bot when start or goal are not passed properly, also a logging error will print out ([08466b5](https://github.com/eladyaniv01/SC2MapAnalysis/commit/08466b5e3650a694bf5b0d633b894fdb6bfbd7b8)) +* [[#61]](https://github.com/eladyaniv01/SC2MapAnalysis/issues/61) pathfind will not crash the bot when start or goal are not passed properly, also a logging error will print out ([08466b5](https://github.com/eladyaniv01/SC2MapAnalysis/commit/08466b5e3650a694bf5b0d633b894fdb6bfbd7b8)) * fix point_to_numpy_array method ([4d56755](https://github.com/eladyaniv01/SC2MapAnalysis/commit/4d567559e3eceede00615c637458cdb8a0870d36)) -* fix point_to_numpy_array method ([24af6b8](https://github.com/eladyaniv01/SC2MapAnalysis/commit/24af6b8c0d9d326235bc4c748887fcb6bf884b45)) -* fix point_to_numpy_array method ([18c4642](https://github.com/eladyaniv01/SC2MapAnalysis/commit/18c464274dee7549bea10352736225f9917bd3c5)) -* mapdata test for plotting ([0ce534b](https://github.com/eladyaniv01/SC2MapAnalysis/commit/0ce534b46839f1b983d5512ebcbbad9644cc37cf)) -* mapdata test for plotting ([3d359b1](https://github.com/eladyaniv01/SC2MapAnalysis/commit/3d359b183806fcb15b67ed64ad816e617278ec19)) * points_to_numpy_array now filters out outofbounds ([aedf9d2](https://github.com/eladyaniv01/SC2MapAnalysis/commit/aedf9d2ba45f585a279d7a014a7e990cbb9359a9)) -* points_to_numpy_array now filters out outofbounds ([f15a360](https://github.com/eladyaniv01/SC2MapAnalysis/commit/f15a360e7a861dc911a3cc08649be1c9b9e4da13)) -* update according to last fix ([486f0f9](https://github.com/eladyaniv01/SC2MapAnalysis/commit/486f0f9346cec936228492aba77e5e7ced22a259)) -* update according to last fix ([dae199b](https://github.com/eladyaniv01/SC2MapAnalysis/commit/dae199bfed3ce509cc4148864508e3a687718455)) + ### [0.0.49](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.48...v0.0.49) (2020-08-12) ### Bug Fixes -* [[#58](https://github.com/eladyaniv01/SC2MapAnalysis/issues/58)](https://github.com/eladyaniv01/SC2MapAnalysis/issues/58) climber_grid is now aware of nonpathables (such as minerals, destructibles etc) ([98dcbec](https://github.com/eladyaniv01/SC2MapAnalysis/commit/98dcbec074e032047d4eacbb5f97e1961f06d395)) -* [[#59](https://github.com/eladyaniv01/SC2MapAnalysis/issues/59)](https://github.com/eladyaniv01/SC2MapAnalysis/issues/59) clean air grid will now accept 'default_weight' argument (MapData, Pather) ([355ab7d](https://github.com/eladyaniv01/SC2MapAnalysis/commit/355ab7d8f0522a905d77007e979d3e57734bc4e7)) +* [#58](https://github.com/eladyaniv01/SC2MapAnalysis/issues/58) climber_grid is now aware of nonpathables (such as minerals, destructibles etc) ([98dcbec](https://github.com/eladyaniv01/SC2MapAnalysis/commit/98dcbec074e032047d4eacbb5f97e1961f06d395)) +* [#59](https://github.com/eladyaniv01/SC2MapAnalysis/issues/59) clean air grid will now accept 'default_weight' argument (MapData, Pather) ([355ab7d](https://github.com/eladyaniv01/SC2MapAnalysis/commit/355ab7d8f0522a905d77007e979d3e57734bc4e7)) * climber_grid tests ([5216d0c](https://github.com/eladyaniv01/SC2MapAnalysis/commit/5216d0c8e796a3284c8e531e2ce4dcf3075582f4)) * import error on region-polygon ([b8ea912](https://github.com/eladyaniv01/SC2MapAnalysis/commit/b8ea9126a6dea792d9d62538688c6d9d15c395d8)) * mapdata test for plotting ([26a7c15](https://github.com/eladyaniv01/SC2MapAnalysis/commit/26a7c154a4a973995cea67267097aae0f9d58681)) From 9618799a50f2fffcb78aa1f802e3903598c9a8ce Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Fri, 14 Aug 2020 14:44:49 +0300 Subject: [PATCH 36/54] fix: __bool__ compatibility with burnysc2 burnysc2 overrides __bool__ for Point2 which causes calling list(map(numpy.array, Point2)) to map the x,y with numpy values ( and the bool check returns numpy_bool instead of __bool__) --- MapAnalyzer/Pather.py | 1 + 1 file changed, 1 insertion(+) diff --git a/MapAnalyzer/Pather.py b/MapAnalyzer/Pather.py index 66ae7367..581d69bd 100644 --- a/MapAnalyzer/Pather.py +++ b/MapAnalyzer/Pather.py @@ -102,6 +102,7 @@ def pathfind(self, start: Tuple[int, int], goal: Tuple[int, int], grid: Optional path = self.pyastar.astar_path(grid, start=start, goal=goal, allow_diagonal=allow_diagonal) if path is not None: + path = path.tolist() # this make the mapping not override the int boolean with numpy boolean return list(map(Point2, path))[::sensitivity] else: self.map_data.logger.debug(f"No Path found s{start}, g{goal}") From 814149535703d700c5dee27cdeffb3fbb2693e85 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Fri, 14 Aug 2020 14:45:26 +0300 Subject: [PATCH 37/54] bump setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0089cf68..776265b1 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ ] setup( # pragma: no cover name="sc2mapanalyzer", - version="0.0.50", + version="0.0.51", install_requires=requirements, setup_requires=["wheel", "numpy"], extras_require={ From 40b93831766ec52461fb4e4c9786a2995d778137 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Fri, 14 Aug 2020 14:45:38 +0300 Subject: [PATCH 38/54] chore(release): 0.0.51 --- CHANGELOG.md | 12 ++++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 748201b3..5ff2f6be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.51](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.50...v0.0.51) (2020-08-14) + + +### Features + +* Polygon/ Region now has the property 'buildable_points' ([#63](https://github.com/eladyaniv01/SC2MapAnalysis/issues/63)) ([2100501](https://github.com/eladyaniv01/SC2MapAnalysis/commit/21005016ab9669dfc276aee4a709e0c24435f2d2)) + + +### Bug Fixes + +* __bool__ compatibility with burnysc2 ([9618799](https://github.com/eladyaniv01/SC2MapAnalysis/commit/9618799a50f2fffcb78aa1f802e3903598c9a8ce)) + ### [0.0.50](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.49...v0.0.50) (2020-08-13) diff --git a/package-lock.json b/package-lock.json index 3c1dd8fa..5b659a04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "Sc2MapAnalyzer", - "version": "0.0.50", + "version": "0.0.51", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f2551307..7509067e 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,4 @@ { "name": "sc2mapanalyzer", - "version": "0.0.50" + "version": "0.0.51" } From 628b380c94079589f339506447f8d7c5b932aff4 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:11:03 +0300 Subject: [PATCH 39/54] feat: Polygon/ Region now has the property 'buildable_points' with some usage ideas --- MapAnalyzer/MapData.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 8a319f3b..7866e3a5 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - rows, cols = self.path_arr.shape + cols, rows = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) if isinstance(points, set): points = list(points) From 86a8fc35cc5eb0de10a775a031c63703c3eed866 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:31:27 +0300 Subject: [PATCH 40/54] fix: fix point_to_numpy_array method --- MapAnalyzer/MapData.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 7866e3a5..8a319f3b 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - cols, rows = self.path_arr.shape + rows, cols = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) if isinstance(points, set): points = list(points) From b987fb6c29863cf57b30abfa5dad3b152456bcab Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:11:25 +0300 Subject: [PATCH 41/54] fix: mapdata test for plotting --- tests/test_suite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_suite.py b/tests/test_suite.py index 56d26247..361ffb75 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -29,7 +29,7 @@ def pytest_generate_tests(metafunc: Metafunc) -> None: def test_mapdata(n, m): map_files = get_map_file_list() map_data = mock_map_data(random.choice(map_files)) - # map_data.plot_map() + map_data.plot_map() logger.info(f"Loaded Map : {map_data.bot.game_info.map_name}, n,m = {n}, {m}") points = [(i, j) for i in range(n + 1) for j in range(m + 1)] set_points = set(points) From 132056d37a34db0ef185dc76a22c01ca553a0fd2 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:11:25 +0300 Subject: [PATCH 42/54] fix: mapdata test for plotting --- tests/test_suite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_suite.py b/tests/test_suite.py index 361ffb75..56d26247 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -29,7 +29,7 @@ def pytest_generate_tests(metafunc: Metafunc) -> None: def test_mapdata(n, m): map_files = get_map_file_list() map_data = mock_map_data(random.choice(map_files)) - map_data.plot_map() + # map_data.plot_map() logger.info(f"Loaded Map : {map_data.bot.game_info.map_name}, n,m = {n}, {m}") points = [(i, j) for i in range(n + 1) for j in range(m + 1)] set_points = set(points) From 3319701c3ffa74f6c1dad7f1f968ba06855ff39c Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:35:28 +0300 Subject: [PATCH 43/54] chore(release): 0.0.49 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ff2f6be..d4c59e4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ All notable changes to this project will be documented in this file. See [standa * climber_grid tests ([5216d0c](https://github.com/eladyaniv01/SC2MapAnalysis/commit/5216d0c8e796a3284c8e531e2ce4dcf3075582f4)) * import error on region-polygon ([b8ea912](https://github.com/eladyaniv01/SC2MapAnalysis/commit/b8ea9126a6dea792d9d62538688c6d9d15c395d8)) * mapdata test for plotting ([26a7c15](https://github.com/eladyaniv01/SC2MapAnalysis/commit/26a7c154a4a973995cea67267097aae0f9d58681)) +* mapdata test for plotting ([6017926](https://github.com/eladyaniv01/SC2MapAnalysis/commit/601792693b08960a96e211495607dce0dd69a943)) * versionbump cli now commits setup.py before calling standard-version ([50eb667](https://github.com/eladyaniv01/SC2MapAnalysis/commit/50eb667c48949a0847742ed5aec8957f07cd8ff9)) From 520f869bc92b31c79b514f3632c67a509bfe940e Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Wed, 12 Aug 2020 19:37:09 +0300 Subject: [PATCH 44/54] clean Changelog --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4c59e4b..5ff2f6be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,7 +39,6 @@ All notable changes to this project will be documented in this file. See [standa * climber_grid tests ([5216d0c](https://github.com/eladyaniv01/SC2MapAnalysis/commit/5216d0c8e796a3284c8e531e2ce4dcf3075582f4)) * import error on region-polygon ([b8ea912](https://github.com/eladyaniv01/SC2MapAnalysis/commit/b8ea9126a6dea792d9d62538688c6d9d15c395d8)) * mapdata test for plotting ([26a7c15](https://github.com/eladyaniv01/SC2MapAnalysis/commit/26a7c154a4a973995cea67267097aae0f9d58681)) -* mapdata test for plotting ([6017926](https://github.com/eladyaniv01/SC2MapAnalysis/commit/601792693b08960a96e211495607dce0dd69a943)) * versionbump cli now commits setup.py before calling standard-version ([50eb667](https://github.com/eladyaniv01/SC2MapAnalysis/commit/50eb667c48949a0847742ed5aec8957f07cd8ff9)) From 8f2444068e71180b8f0e1198d20ec5228504dc46 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:11:03 +0300 Subject: [PATCH 45/54] feat: Polygon/ Region now has the property 'buildable_points' with some usage ideas --- MapAnalyzer/MapData.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 8a319f3b..7866e3a5 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - rows, cols = self.path_arr.shape + cols, rows = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) if isinstance(points, set): points = list(points) From 5c1b4867b2cc19353d0bdad7d0e1c99d26259072 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:31:27 +0300 Subject: [PATCH 46/54] fix: fix point_to_numpy_array method --- MapAnalyzer/MapData.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 7866e3a5..8a319f3b 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - cols, rows = self.path_arr.shape + rows, cols = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) if isinstance(points, set): points = list(points) From 8f45843178b88d4a725d90a63813aecbf8b89c2b Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:11:03 +0300 Subject: [PATCH 47/54] feat: Polygon/ Region now has the property 'buildable_points' with some usage ideas --- MapAnalyzer/MapData.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 8a319f3b..7866e3a5 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - rows, cols = self.path_arr.shape + cols, rows = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) if isinstance(points, set): points = list(points) From ff6d104e3b7e125c93e916d24703aa4496764062 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Thu, 13 Aug 2020 01:31:27 +0300 Subject: [PATCH 48/54] fix: fix point_to_numpy_array method --- MapAnalyzer/MapData.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 7866e3a5..8a319f3b 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -167,7 +167,7 @@ def points_to_numpy_array( """ convert points to numpy ndarray """ - cols, rows = self.path_arr.shape + rows, cols = self.path_arr.shape arr = np.zeros((rows, cols), dtype=np.uint8) if isinstance(points, set): points = list(points) From 209d6d1c065893f98ce6bbfaeb34ab38b74e41a9 Mon Sep 17 00:00:00 2001 From: eladyaniv01 <40754127+eladyaniv01@users.noreply.github.com> Date: Sat, 15 Aug 2020 04:10:57 +0300 Subject: [PATCH 49/54] Base (#65) * refactor: Region to inherit from Polygon + adjusted tests BREAKING CHANGE: Region is now a Child of Polygon * fix: __bool__ compatibility with burnysc2 (#64) * fix: regions and ramps now set each other correctly --- .github/workflows/build_on_setup.yml | 2 +- MapAnalyzer/Debugger.py | 10 ++-- MapAnalyzer/MapData.py | 51 ++++-------------- MapAnalyzer/Pather.py | 10 ++-- MapAnalyzer/Polygon.py | 24 ++++++--- MapAnalyzer/Region.py | 81 ++++++---------------------- MapAnalyzer/constructs.py | 44 +++++++++------ tests/test_suite.py | 7 ++- 8 files changed, 85 insertions(+), 144 deletions(-) diff --git a/.github/workflows/build_on_setup.yml b/.github/workflows/build_on_setup.yml index 7f56d1fb..fd0ef55d 100644 --- a/.github/workflows/build_on_setup.yml +++ b/.github/workflows/build_on_setup.yml @@ -2,7 +2,7 @@ name: BuildOnSetup on: push: - branches: [ master, dev ] + branches: [ master, dev, Base ] pull_request: branches: [ master, dev ] diff --git a/MapAnalyzer/Debugger.py b/MapAnalyzer/Debugger.py index 326fffaf..eafb908c 100644 --- a/MapAnalyzer/Debugger.py +++ b/MapAnalyzer/Debugger.py @@ -66,10 +66,10 @@ def plot_regions(self, fontdict: Dict[str, Union[str, int]]) -> None: import matplotlib.pyplot as plt for lbl, reg in self.map_data.regions.items(): c = COLORS[lbl] - fontdict["color"] = c + fontdict["color"] = 'black' fontdict["backgroundcolor"] = 'black' - if c == 'black': - fontdict["backgroundcolor"] = 'white' + # if c == 'black': + # fontdict["backgroundcolor"] = 'white' plt.text( reg.center[0], reg.center[1], @@ -78,9 +78,9 @@ def plot_regions(self, fontdict: Dict[str, Union[str, int]]) -> None: fontdict=fontdict, ) # random color for each perimeter - x, y = zip(*reg.polygon.perimeter_points) + x, y = zip(*reg.perimeter_points) plt.scatter(x, y, c=c, marker="1", s=300) - for corner in reg.polygon.corner_points: + for corner in reg.corner_points: plt.scatter(corner[0], corner[1], marker="v", c="red", s=150) def plot_vision_blockers(self) -> None: diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 8a319f3b..412e5ace 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -249,7 +249,7 @@ def where_all( point = int(point[0]), int(point[1]) for region in self.regions.values(): - if region.inside_p(point): + if region.is_inside_point(point): results.append(region) for choke in self.map_chokes: if choke.is_inside_point(point): @@ -275,7 +275,7 @@ def where( point = int(point[0]), int(point[1]) for region in self.regions.values(): - if region.inside_p(point): + if region.is_inside_point(point): return region for choke in self.map_chokes: if choke.is_inside_point(point): @@ -356,28 +356,22 @@ def compile_map(self) -> None: self._calc_grid() self._calc_regions() self._calc_vision_blockers() + self._set_map_ramps() self._calc_chokes() self._clean_polys() + for poly in self.polygons: poly.calc_areas() - - @staticmethod - def _clean_ramps(region: Region) -> None: - """ utility function to remove over populated ramps """ - for mramp in region.region_ramps: - if len(mramp.regions) < 2: - region.region_ramps.remove(mramp) + for ramp in self.map_ramps: + ramp.set_regions() def _calc_grid(self) -> None: """ converting the placement grid to our own kind of grid""" # cleaning the grid and then searching for 2x2 patterned regions grid = binary_fill_holes(self.placement_arr).astype(int) # for our grid, mineral walls are considered as a barrier between regions - correct_blockers = [] for point in self.resource_blockers: grid[int(point[0])][int(point[1])] = 0 - if point not in self.resource_blockers: - correct_blockers.append(point) for n in point.neighbors4: point_ = Point2((n.rounded[0], n.rounded[1])) if point_[0] < grid.shape[1] and point_[1] < grid.shape[0]: @@ -409,36 +403,7 @@ def _set_map_ramps(self): array=self.points_to_numpy_array(r.points)) for r in self.bot.game_info.map_ramps] - def _calc_ramps(self, region: Region) -> None: - """ - probably the most expensive operation other than plotting , need to optimize - """ - if len(self.map_ramps) == 0: - self._set_map_ramps() - - ramp_nodes = self.get_ramp_nodes() - perimeter_nodes = region.polygon.perimeter_points - result_ramp_indexes = list(set([self.closest_node_idx(n, ramp_nodes) for n in perimeter_nodes])) - - for rn in result_ramp_indexes: - # and distance from perimeter is less than ? - ramp = self.get_ramp(node=ramp_nodes[rn]) - - """for ramp in map ramps if ramp exists, append the regions if not, create new one""" - if region not in ramp.areas: - ramp.areas.append(region) - region.region_ramps.append(ramp) - ramps = [] - - for ramp in region.region_ramps: - for p in region.polygon.perimeter_points: - if self.ramp_close_enough(ramp, p, n=8): - ramps.append(ramp) - ramps = list(set(ramps)) - region.region_ramps.extend(ramps) - region.region_ramps = list(set(region.region_ramps)) - # self._clean_ramps(region) def _calc_vision_blockers(self) -> None: """ @@ -497,6 +462,8 @@ def _calc_regions(self) -> None: """ # some areas are with area of 1, 2 ,5 these are not what we want, # so we filter those out + # if len(self.map_ramps) == 0: + # self._set_map_ramps() pre_regions = {} for i in range(len(self.regions_labels)): region = Region( @@ -513,7 +480,7 @@ def _calc_regions(self) -> None: if self.max_region_area > region.get_area > self.min_region_area: region.label = j self.regions[j] = region - self._calc_ramps(region=region) + # region.calc_ramps() j += 1 """Plot methods""" diff --git a/MapAnalyzer/Pather.py b/MapAnalyzer/Pather.py index 581d69bd..4a1d3ba0 100644 --- a/MapAnalyzer/Pather.py +++ b/MapAnalyzer/Pather.py @@ -1,4 +1,3 @@ -from functools import lru_cache from typing import Optional, Tuple, TYPE_CHECKING import numpy as np @@ -46,7 +45,9 @@ def _add_non_pathables_ground(self, grid: ndarray, include_destructables: bool = nonpathables.extend(self.map_data.mineral_fields) for obj in nonpathables: radius = NONPATHABLE_RADIUS - grid = self.add_influence(p=obj.position, r=radius * obj.radius, arr=grid, weight=np.inf) + if 'mineral' in obj.name.lower(): + radius = NONPATHABLE_RADIUS * 1.5 + grid = self.add_influence(p=obj.position.rounded, r=radius * obj.radius, arr=grid, weight=np.inf) for pos in self.map_data.resource_blockers: radius = RESOURCE_BLOCKER_RADIUS grid = self.add_influence(p=pos, r=radius, arr=grid, weight=np.inf) @@ -57,11 +58,9 @@ def _add_non_pathables_ground(self, grid: ndarray, include_destructables: bool = self.add_influence(p=rock.position, r=1 * rock.radius, arr=grid, weight=np.inf) return grid - @lru_cache() def get_base_pathing_grid(self) -> ndarray: return np.fmax(self.map_data.path_arr, self.map_data.placement_arr).T - @lru_cache() def get_climber_grid(self, default_weight: int = 1, include_destructables: bool = True) -> ndarray: """Grid for units like reaper / colossus """ grid = self._climber_grid.copy() @@ -69,7 +68,6 @@ def get_climber_grid(self, default_weight: int = 1, include_destructables: bool grid = self._add_non_pathables_ground(grid=grid, include_destructables=include_destructables) return grid - @lru_cache() def get_clean_air_grid(self, default_weight: int = 1): clean_air_grid = np.ones(shape=self.map_data.path_arr.shape).astype(np.float32).T if default_weight == 1: @@ -77,7 +75,6 @@ def get_clean_air_grid(self, default_weight: int = 1): else: return np.where(clean_air_grid == 1, default_weight, 0) - @lru_cache() def get_air_vs_ground_grid(self, default_weight: int): grid = np.fmin(self.map_data.path_arr, self.map_data.placement_arr) air_vs_ground_grid = np.where(grid == 0, 1, default_weight).astype(np.float32) @@ -113,6 +110,7 @@ def add_influence(self, p: Tuple[int, int], r: int, arr: ndarray, weight: int = if len(ri) == 0 or len(ci) == 0: # this happens when the center point is near map edge, and the radius added goes beyond the edge self.map_data.logger.debug(OutOfBoundsException(p)) + # self.map_data.logger.trace() return arr def in_bounds_ci(x): diff --git a/MapAnalyzer/Polygon.py b/MapAnalyzer/Polygon.py index 07731852..f7cd35c5 100644 --- a/MapAnalyzer/Polygon.py +++ b/MapAnalyzer/Polygon.py @@ -18,13 +18,13 @@ def __init__(self, polygon): self.points = None @property - def free_pct(self): + def free_pct(self) -> float: if self.points is None: self.polygon.map_data.logger.warning("BuildablePoints needs to update first") self.update() return len(self.points) / len(self.polygon.points) - def update(self): + def update(self) -> None: parr = self.polygon.map_data.points_to_numpy_array(self.polygon.points) [self.polygon.map_data.add_influence(p=(unit.position.x, unit.position.y), r=unit.radius, arr=parr, safe=False) for unit in @@ -66,14 +66,14 @@ def __init__(self, map_data: "MapData", array: ndarray) -> None: # pragma: no c self.indices = self.map_data.points_to_indices(self.points) self.map_data.polygons.append(self) self._buildable_points = BuildablePoints(polygon=self) + # self.calc_areas() @property - def buildable_points(self): + def buildable_points(self) -> BuildablePoints: self._buildable_points.update() return self._buildable_points @property - @lru_cache() def regions(self) -> List["Region"]: from MapAnalyzer.Region import Region if len(self.areas) > 0: @@ -81,7 +81,17 @@ def regions(self) -> List["Region"]: return [] def calc_areas(self) -> None: - pass + # this method uses where_all which means + # it should be called at the end of the map compilation when areas are populated + points = [min(self.points), max(self.points)] + areas = self.areas + for point in points: + point = int(point[0]), int(point[1]) + new_areas = self.map_data.where_all(point) + if self in new_areas: + new_areas.pop(new_areas.index(self)) + areas.extend(new_areas) + self.areas = list(set(areas)) def plot(self, testing: bool = False) -> None: # pragma: no cover """ @@ -150,7 +160,7 @@ def center(self) -> Point2: cm = self.map_data.closest_towards_point(points=self.clean_points, target=center_of_mass(self.array)) return cm - @lru_cache(100) + @lru_cache() def is_inside_point(self, point: Union[Point2, tuple]) -> bool: """ is_inside_point @@ -161,7 +171,7 @@ def is_inside_point(self, point: Union[Point2, tuple]) -> bool: return True return False - @lru_cache(100) + @lru_cache() def is_inside_indices( self, point: Union[Point2, tuple] ) -> bool: # pragma: no cover diff --git a/MapAnalyzer/Region.py b/MapAnalyzer/Region.py index 8b1eb5c5..73c523c8 100644 --- a/MapAnalyzer/Region.py +++ b/MapAnalyzer/Region.py @@ -1,5 +1,4 @@ -from functools import lru_cache -from typing import List, TYPE_CHECKING, Union +from typing import List, TYPE_CHECKING import numpy as np from sc2.position import Point2 @@ -10,11 +9,7 @@ from MapAnalyzer import MapData -class Region: - """ - Region DocString - """ - +class Region(Polygon): def __init__( self, map_data: 'MapData', @@ -22,40 +17,30 @@ def __init__( label: int, map_expansions: List[Point2], ) -> None: + super().__init__(map_data=map_data, array=array) self.map_data = map_data self.array = array self.label = label - - self.polygon = Polygon(map_data=self.map_data, array=self.array) # for constructor - self.polygon.areas.append(self) - self.polygon.is_region = True + self.is_region = True self.bases = [ base for base in map_expansions - if self.polygon.is_inside_point((base.rounded[0], base.rounded[1])) - ] - self.region_ramps = [] # will be set later by mapdata + if self.is_inside_point((base.rounded[0], base.rounded[1])) + ] # will be set later by mapdata self.region_vision_blockers = [] # will be set later by mapdata self.region_vb = [] self.region_chokes = [] @property - def buildable_points(self): - return self.polygon.buildable_points - - @property - def center(self) -> Point2: - """ - center - """ - return self.polygon.center + def region_ramps(self): + return [r for r in self.areas if r.is_ramp] @property def corners(self) -> List[Point2]: """ corners """ - return self.polygon.corner_points + return self.corner_points def plot_perimeter(self, self_only: bool = True) -> None: """ @@ -65,7 +50,7 @@ def plot_perimeter(self, self_only: bool = True) -> None: plt.style.use("ggplot") - x, y = zip(*self.polygon.perimeter) # reversing for "lower" origin + x, y = zip(*self.perimeter) # reversing for "lower" origin plt.scatter(x, y) plt.title(f"Region {self.label}") if self_only: # pragma: no cover @@ -74,7 +59,7 @@ def plot_perimeter(self, self_only: bool = True) -> None: def _plot_corners(self) -> None: import matplotlib.pyplot as plt plt.style.use("ggplot") - for corner in self.polygon.corner_points: + for corner in self.corner_points: plt.scatter(corner[0], corner[1], marker="v", c="red", s=150) def _plot_ramps(self) -> None: @@ -103,7 +88,7 @@ def _plot_vision_blockers(self) -> None: plt.style.use("ggplot") for vb in self.map_data.vision_blockers: - if self.inside_p(point=vb): + if self.is_inside_point(point=vb): plt.text(vb[0], vb[1], "X", c="r") def _plot_minerals(self) -> None: @@ -114,7 +99,7 @@ def _plot_minerals(self) -> None: plt.style.use("ggplot") for mineral_field in self.map_data.mineral_fields: - if self.inside_p(mineral_field.position.rounded): + if self.is_inside_point(mineral_field.position.rounded): plt.scatter( mineral_field.position[0], mineral_field.position[1], color="blue" ) @@ -127,7 +112,7 @@ def _plot_geysers(self) -> None: plt.style.use("ggplot") for gasgeyser in self.map_data.normal_geysers: - if self.inside_p(gasgeyser.position.rounded): + if self.is_inside_point(gasgeyser.position.rounded): plt.scatter( gasgeyser.position[0], gasgeyser.position[1], @@ -157,20 +142,6 @@ def plot(self, self_only: bool = True, testing: bool = False) -> None: else: # pragma: no cover self.plot_perimeter(self_only=False) - @lru_cache(100) - def inside_p(self, point: Union[Point2, tuple]) -> bool: - """ - inside_p - """ - return self.polygon.is_inside_point(point) - - @lru_cache(100) - def inside_i(self, point: Union[Point2, tuple]) -> bool: # pragma: no cover - """ - inside_i - """ - return self.polygon.is_inside_indices(point) - @property def base_locations(self) -> List[Point2]: """ @@ -178,34 +149,12 @@ def base_locations(self) -> List[Point2]: """ return self.bases - # @property - # def is_reachable(self, areas): # pragma: no cover - # """ - # is connected to another areas directly - # :param areas: - # :type areas: - # :return: - # :rtype: - # """ - # pass - - @property - def get_reachable_regions(self): - """ - """ - result = [] - for r in self.region_ramps: - for reg in r.regions: - if reg != self: - result.append((str(r), reg)) - return set(result) - @property def get_area(self) -> int: """ get_area """ - return self.polygon.area + return self.area def __repr__(self) -> str: # pragma: no cover """ diff --git a/MapAnalyzer/constructs.py b/MapAnalyzer/constructs.py index a4459c80..d1ea5cc2 100644 --- a/MapAnalyzer/constructs.py +++ b/MapAnalyzer/constructs.py @@ -41,18 +41,6 @@ def __init__( self.md_pl_choke = pathlibchoke self.is_choke = True - def calc_areas(self) -> None: - if self.main_line: - points = [min(self.points), max(self.points)] - areas = self.areas - for point in points: - point = int(point[0]), int(point[1]) - new_areas = self.map_data.where_all(point) - if self in new_areas: - new_areas.pop(new_areas.index(self)) - areas.extend(new_areas) - self.areas = list(set(areas)) - def __repr__(self) -> str: # pragma: no cover return f"<[{self.id}]ChokeArea[size={self.area}]> of {self.areas}" @@ -67,8 +55,34 @@ def __init__(self, map_data: "MapData", array: np.ndarray, ramp: sc2Ramp) -> Non self.is_ramp = True self.ramp = ramp - def calc_areas(self) -> None: - return + def closest_region(self, region_list): + return min(region_list, + key=lambda area: min(self.map_data.distance(area.center, point) for point in self.perimeter_points)) + + def set_regions(self): + from MapAnalyzer.Region import Region + for p in self.perimeter_points: + areas = self.map_data.where_all(p) + for area in areas: + if isinstance(area, VisionBlockerArea): + for sub_area in area.areas: + if isinstance(sub_area, Region) and sub_area not in self.areas: + self.areas.append(sub_area) + if isinstance(sub_area, Region) and self not in sub_area.areas: + sub_area.areas.append(self) + if isinstance(area, Region) and area not in self.areas: + self.areas.append(area) + # add ourselves to the Region Area's + if isinstance(area, Region) and self not in area.areas: + area.areas.append(self) + if len(self.regions) < 2: + # destructables blocking the ramp ? + # mineral walls ? + region_list = list(self.map_data.regions.values()) + region_list.remove(self.regions[0]) + closest_region = self.closest_region(region_list=region_list) + assert (closest_region not in self.regions) + self.areas.append(closest_region) @property def top_center(self) -> Point2: @@ -88,7 +102,7 @@ def bottom_center(self) -> Point2: self.map_data.logger.debug(f"No bottom_center found for {self}, falling back to `center`") return self.center - def __repr__(self): # pragma: no cover + def __repr__(self) -> str: # pragma: no cover return f"" def __str__(self): diff --git a/tests/test_suite.py b/tests/test_suite.py index 56d26247..b30cd18c 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -71,7 +71,7 @@ def test_polygon(self, map_data: MapData) -> None: def test_regions(self, map_data: MapData) -> None: for region in map_data.regions.values(): - for p in region.polygon.points: + for p in region.points: assert isinstance( map_data.where(p), Region # using where because the first return will be always Region ), f" None: assert (region in map_data.where_all(region.center)) assert (region == map_data.where(region.center)) - assert (region.corners is region.polygon.corner_points) # coverage region.plot(testing=True) + def test_ramps(self, map_data: MapData) -> None: + for ramp in map_data.map_ramps: + assert (len(ramp.regions) == 2), f"ramp = {ramp}" + def test_chokes(self, map_data: MapData) -> None: for choke in map_data.map_chokes: for p in choke.points: From a491b3f71d7f2917f940f9d4acb2ed2e927d4ee4 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Sat, 15 Aug 2020 19:29:22 +0300 Subject: [PATCH 50/54] style: removed redundant comments --- MapAnalyzer/Region.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MapAnalyzer/Region.py b/MapAnalyzer/Region.py index 73c523c8..4a29acac 100644 --- a/MapAnalyzer/Region.py +++ b/MapAnalyzer/Region.py @@ -4,6 +4,7 @@ from sc2.position import Point2 from MapAnalyzer.Polygon import Polygon +from MapAnalyzer.constructs import MDRamp if TYPE_CHECKING: from MapAnalyzer import MapData @@ -32,7 +33,7 @@ def __init__( self.region_chokes = [] @property - def region_ramps(self): + def region_ramps(self) -> List[MDRamp]: return [r for r in self.areas if r.is_ramp] @property @@ -50,7 +51,7 @@ def plot_perimeter(self, self_only: bool = True) -> None: plt.style.use("ggplot") - x, y = zip(*self.perimeter) # reversing for "lower" origin + x, y = zip(*self.perimeter) plt.scatter(x, y) plt.title(f"Region {self.label}") if self_only: # pragma: no cover From 730c9ea21da4fb67f2ad0911330a8535246fca79 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Sat, 15 Aug 2020 19:29:43 +0300 Subject: [PATCH 51/54] bump setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 776265b1..8ab26cff 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ ] setup( # pragma: no cover name="sc2mapanalyzer", - version="0.0.51", + version="0.0.52", install_requires=requirements, setup_requires=["wheel", "numpy"], extras_require={ From 1f077b79856fbc33577daa6b683be54865f54a9a Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Sat, 15 Aug 2020 19:30:05 +0300 Subject: [PATCH 52/54] chore(release): 0.0.52 --- CHANGELOG.md | 25 +++++++++++++++++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ff2f6be..458c4192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,31 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.52](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.51...v0.0.52) (2020-08-15) + + +### ⚠ BREAKING CHANGES + +* Region is now a Child of Polygon + +### Features + +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([8f45843](https://github.com/eladyaniv01/SC2MapAnalysis/commit/8f45843178b88d4a725d90a63813aecbf8b89c2b)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([8f24440](https://github.com/eladyaniv01/SC2MapAnalysis/commit/8f2444068e71180b8f0e1198d20ec5228504dc46)) +* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([628b380](https://github.com/eladyaniv01/SC2MapAnalysis/commit/628b380c94079589f339506447f8d7c5b932aff4)) + + +### Bug Fixes + +* fix point_to_numpy_array method ([ff6d104](https://github.com/eladyaniv01/SC2MapAnalysis/commit/ff6d104e3b7e125c93e916d24703aa4496764062)) +* fix point_to_numpy_array method ([5c1b486](https://github.com/eladyaniv01/SC2MapAnalysis/commit/5c1b4867b2cc19353d0bdad7d0e1c99d26259072)) +* fix point_to_numpy_array method ([86a8fc3](https://github.com/eladyaniv01/SC2MapAnalysis/commit/86a8fc35cc5eb0de10a775a031c63703c3eed866)) +* mapdata test for plotting ([132056d](https://github.com/eladyaniv01/SC2MapAnalysis/commit/132056d37a34db0ef185dc76a22c01ca553a0fd2)) +* mapdata test for plotting ([b987fb6](https://github.com/eladyaniv01/SC2MapAnalysis/commit/b987fb6c29863cf57b30abfa5dad3b152456bcab)) + + +* Base (#65) ([209d6d1](https://github.com/eladyaniv01/SC2MapAnalysis/commit/209d6d1c065893f98ce6bbfaeb34ab38b74e41a9)), closes [#65](https://github.com/eladyaniv01/SC2MapAnalysis/issues/65) [#64](https://github.com/eladyaniv01/SC2MapAnalysis/issues/64) + ### [0.0.51](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.50...v0.0.51) (2020-08-14) diff --git a/package-lock.json b/package-lock.json index 5b659a04..b66c5806 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "Sc2MapAnalyzer", - "version": "0.0.51", + "version": "0.0.52", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7509067e..a5a81381 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,4 @@ { "name": "sc2mapanalyzer", - "version": "0.0.51" + "version": "0.0.52" } From e07c8c129c65226acdfb7af749f2136e6a0c0ebe Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Sat, 15 Aug 2020 19:40:09 +0300 Subject: [PATCH 53/54] docs: clean up changelog, add log_module to constants --- CHANGELOG.md | 13 ------------- MapAnalyzer/Debugger.py | 15 +++++++++------ MapAnalyzer/constants.py | 3 ++- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 458c4192..dddf3319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,27 +4,14 @@ All notable changes to this project will be documented in this file. See [standa ### [0.0.52](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.51...v0.0.52) (2020-08-15) - ### ⚠ BREAKING CHANGES * Region is now a Child of Polygon -### Features - -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([8f45843](https://github.com/eladyaniv01/SC2MapAnalysis/commit/8f45843178b88d4a725d90a63813aecbf8b89c2b)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([8f24440](https://github.com/eladyaniv01/SC2MapAnalysis/commit/8f2444068e71180b8f0e1198d20ec5228504dc46)) -* Polygon/ Region now has the property 'buildable_points' with some usage ideas ([628b380](https://github.com/eladyaniv01/SC2MapAnalysis/commit/628b380c94079589f339506447f8d7c5b932aff4)) - - ### Bug Fixes -* fix point_to_numpy_array method ([ff6d104](https://github.com/eladyaniv01/SC2MapAnalysis/commit/ff6d104e3b7e125c93e916d24703aa4496764062)) -* fix point_to_numpy_array method ([5c1b486](https://github.com/eladyaniv01/SC2MapAnalysis/commit/5c1b4867b2cc19353d0bdad7d0e1c99d26259072)) -* fix point_to_numpy_array method ([86a8fc3](https://github.com/eladyaniv01/SC2MapAnalysis/commit/86a8fc35cc5eb0de10a775a031c63703c3eed866)) -* mapdata test for plotting ([132056d](https://github.com/eladyaniv01/SC2MapAnalysis/commit/132056d37a34db0ef185dc76a22c01ca553a0fd2)) * mapdata test for plotting ([b987fb6](https://github.com/eladyaniv01/SC2MapAnalysis/commit/b987fb6c29863cf57b30abfa5dad3b152456bcab)) - * Base (#65) ([209d6d1](https://github.com/eladyaniv01/SC2MapAnalysis/commit/209d6d1c065893f98ce6bbfaeb34ab38b74e41a9)), closes [#65](https://github.com/eladyaniv01/SC2MapAnalysis/issues/65) [#64](https://github.com/eladyaniv01/SC2MapAnalysis/issues/64) ### [0.0.51](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.50...v0.0.51) (2020-08-14) diff --git a/MapAnalyzer/Debugger.py b/MapAnalyzer/Debugger.py index eafb908c..5aa6afc9 100644 --- a/MapAnalyzer/Debugger.py +++ b/MapAnalyzer/Debugger.py @@ -8,25 +8,28 @@ from loguru import logger from numpy import int64, ndarray -from .constants import COLORS, LOG_FORMAT +from .constants import COLORS, LOG_FORMAT, LOG_MODULE if TYPE_CHECKING: from MapAnalyzer.MapData import MapData class LogFilter: - def __init__(self, module_name: str) -> None: + def __init__(self, module_name: str, level="ERROR") -> None: self.module_name = module_name + self.level = level def __call__(self, record: Dict[str, Any]) -> bool: - # return True + levelno = logger.level(self.level).no if self.module_name.lower() in record["name"].lower() or 'main' in record["name"].lower(): - return True + return record["level"].no >= levelno return False class MapAnalyzerDebugger: - """""" + """ + MapAnalyzerDebugger + """ def __init__(self, map_data: "MapData", loglevel: str = "ERROR") -> None: self.map_data = map_data @@ -34,7 +37,7 @@ def __init__(self, map_data: "MapData", loglevel: str = "ERROR") -> None: self.warnings.filterwarnings('ignore', category=DeprecationWarning) self.warnings.filterwarnings('ignore', category=RuntimeWarning) self.logger = logger - self.log_filter = LogFilter("MapAnalyzer") + self.log_filter = LogFilter(module_name=LOG_MODULE, level=loglevel) self.logger.remove() self.log_format = LOG_FORMAT self.logger.add(sys.stderr, format=self.log_format, filter=self.log_filter) diff --git a/MapAnalyzer/constants.py b/MapAnalyzer/constants.py index d3d60e74..e24b025c 100644 --- a/MapAnalyzer/constants.py +++ b/MapAnalyzer/constants.py @@ -3,6 +3,7 @@ BINARY_STRUCTURE = 2 RESOURCE_BLOCKER_RADIUS = 2 NONPATHABLE_RADIUS = 0.8 +LOG_MODULE = "MapAnalyzer" COLORS = { 0 : "azure", 1 : 'black', @@ -30,4 +31,4 @@ "{level: <8}|{name: ^15}|" \ "{function: ^15}|" \ "{line: >4}|" \ - "{level.icon}{message}" + " {level.icon} {message}" From 168f244ed0679d7633899507ca5cecd2c6a9dda3 Mon Sep 17 00:00:00 2001 From: eladyaniv01 Date: Sat, 15 Aug 2020 19:43:04 +0300 Subject: [PATCH 54/54] clean up changelog --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dddf3319..648c60c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,16 +6,18 @@ All notable changes to this project will be documented in this file. See [standa ### ⚠ BREAKING CHANGES -* Region is now a Child of Polygon +* Region is now a Child of Polygon (Refactor) ### Bug Fixes +* regions and ramps now set each other correctly + * mapdata test for plotting ([b987fb6](https://github.com/eladyaniv01/SC2MapAnalysis/commit/b987fb6c29863cf57b30abfa5dad3b152456bcab)) * Base (#65) ([209d6d1](https://github.com/eladyaniv01/SC2MapAnalysis/commit/209d6d1c065893f98ce6bbfaeb34ab38b74e41a9)), closes [#65](https://github.com/eladyaniv01/SC2MapAnalysis/issues/65) [#64](https://github.com/eladyaniv01/SC2MapAnalysis/issues/64) -### [0.0.51](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.50...v0.0.51) (2020-08-14) +### [0.0.51](https://github.com/eladyaniv01/SC2MapAnalysis/compare/v0.0.50...v0.0.51) (2020-08-14) ### Features