diff --git a/MapAnalyzer/MapData.py b/MapAnalyzer/MapData.py index 5ad835df..56c3abea 100644 --- a/MapAnalyzer/MapData.py +++ b/MapAnalyzer/MapData.py @@ -125,7 +125,7 @@ def get_pyastar_grid(self, default_weight: int = 1, include_destructables: bool * :meth:`.MapData.get_climber_grid` * :meth:`.MapData.get_air_vs_ground_grid` * :meth:`.MapData.get_clean_air_grid` - * :meth:`.MapData.add_influence` + * :meth:`.MapData.add_cost` * :meth:`.MapData.pathfind` """ @@ -156,7 +156,7 @@ def get_climber_grid(self, default_weight: int = 1) -> ndarray: * :meth:`.MapData.get_pyastar_grid` * :meth:`.MapData.get_air_vs_ground_grid` * :meth:`.MapData.get_clean_air_grid` - * :meth:`.MapData.add_influence` + * :meth:`.MapData.add_cost` * :meth:`.MapData.pathfind` """ return self.pather.get_climber_grid(default_weight) @@ -178,7 +178,7 @@ def get_air_vs_ground_grid(self, default_weight: int = 100): * :meth:`.MapData.get_pyastar_grid` * :meth:`.MapData.get_climber_grid` * :meth:`.MapData.get_clean_air_grid` - * :meth:`.MapData.add_influence` + * :meth:`.MapData.add_cost` * :meth:`.MapData.pathfind` """ @@ -199,7 +199,7 @@ def pathfind(self, start: Union[Tuple[int, int], Point2], goal: Union[Tuple[int, grid: Optional[ndarray] = None, allow_diagonal: bool = False, sensitivity: int = 1) -> Union[List[Point2], None]: """ - :rtype: Union[List[:class:`.Point2`], None] + :rtype: Union[List[:class:`sc2.position.Point2`], None] Will return the path with lowest cost (sum) given a weighted array (``grid``), ``start`` , and ``goal``. **If no** ``grid`` **has been provided**, will request a fresh grid from :mod:`.Pather` @@ -239,18 +239,18 @@ def pathfind(self, start: Union[Tuple[int, int], Point2], goal: Union[Tuple[int, return self.pather.pathfind(start=start, goal=goal, grid=grid, allow_diagonal=allow_diagonal, sensitivity=sensitivity) - def add_influence(self, p: Tuple[int, int], r: int, arr: ndarray, weight: int = 100, safe: bool = True, - ) -> ndarray: + def add_cost(self, position: Tuple[int, int], radius: int, grid: ndarray, weight: int = 100, safe: bool = True, + ) -> ndarray: """ :rtype: numpy.ndarray - Will add cost to a `circle-shaped` area with a center ``p`` and radius ``r`` + Will add cost to a `circle-shaped` area with a center ``position`` and radius ``radius`` weight of 100 Warning: When ``safe=False`` the Pather will not adjust illegal values below 1 which could result in a crash` """ - return self.pather.add_influence(p=p, r=r, arr=arr, weight=weight, safe=safe) + return self.pather.add_influence(p=position, r=radius, arr=grid, weight=weight, safe=safe) """Utility methods""" @@ -283,7 +283,7 @@ def indices_to_points( indices: Union[ndarray, Tuple[ndarray, ndarray]] ) -> Set[Union[Tuple[int64, int64], Point2]]: """ - :rtype: Set[Union[Tuple[int64, int64], :class:`.Point2`]] + :rtype: Set[Union[Tuple[int64, int64], :class:`sc2.position.Point2`]] Convert indices to a set of points(``tuples``, not ``Point2`` ) Will only work when both dimensions are of same length """ @@ -337,7 +337,7 @@ def in_bounds_y(y): @staticmethod def distance(p1: Point2, p2: Point2) -> float64: """ - :rtype: float64 + :rtype: numpy.float64 Euclidean distance """ return abs(p2[0] - p1[0]) + abs(p2[1] - p1[1]) @@ -358,7 +358,7 @@ def closest_towards_point( self, points: List[Point2], target: Union[Point2, tuple] ) -> Point2: """ - :rtype: :class:`.Point2` + :rtype: :class:`sc2.position.Point2` Given a list/set of points, and a target, will return the point that is closest to that target diff --git a/MapAnalyzer/Polygon.py b/MapAnalyzer/Polygon.py index 08e97b8a..4c924b7c 100644 --- a/MapAnalyzer/Polygon.py +++ b/MapAnalyzer/Polygon.py @@ -26,7 +26,8 @@ def free_pct(self) -> float: 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) + [self.polygon.map_data.add_cost(position=(unit.position.x, unit.position.y), radius=unit.radius, grid=parr, + safe=False) for unit in self.polygon.map_data.bot.all_units] buildable_indices = np.where(parr == 1) diff --git a/README.md b/README.md index a2ec00b3..0db6e76a 100644 --- a/README.md +++ b/README.md @@ -164,11 +164,11 @@ getting the basic pathing grid : Adding influence : ------------------ -`def add_influence(p: Tuple[int, int], r: int, arr: ndarray, weight: int = 100) -> ndarray:` +`def add_cost(p: Tuple[int, int], r: int, arr: ndarray, weight: int = 100) -> ndarray:` Usage: -`map_data.add_influence(p, r, arr, weight)` +`map_data.add_cost(p, r, arr, weight)` * `p`: center point (for example p could be an enemy units position) * `r`: radius (for example r -> attack range) @@ -257,7 +257,7 @@ for idx in range(8): r = 7 + idx # note that we use the default weight of 100, we could pass custom weights for each point though for p in pts: - arr = map_data.add_influence(p, r, arr, weight=-100) + arr = map_data.add_cost(p, r, arr, weight=-100) """Plot path on weighted grid""" map_data.plot_influenced_path(start=p0, goal=p1, weight_array=arr, name=f"Added {NUM_POINTS} of influence", @@ -287,9 +287,9 @@ from typing import List import sc2 from sc2.player import Bot, Computer -from sc2.position import Point3 +from sc2.position import Point3, Point2 -from MapAnalyzer import MapData, Point2 +from MapAnalyzer import MapData GREEN = Point3((0, 255, 0)) RED = Point3((255, 0, 0)) diff --git a/dummybot.py b/dummybot.py index 2d600b86..27274135 100644 --- a/dummybot.py +++ b/dummybot.py @@ -3,9 +3,9 @@ import sc2 from sc2.player import Bot, Computer -from sc2.position import Point3 +from sc2.position import Point3, Point2 -from MapAnalyzer import MapData, Point2 +from MapAnalyzer import MapData GREEN = Point3((0, 255, 0)) RED = Point3((255, 0, 0)) @@ -57,7 +57,7 @@ async def on_start(self): # for tup in self.influence_points: # p = tup[0] # r = tup[1] - # self.map_data.add_influence(p, r=r, arr=self.influence_grid) + # self.map_data.add_cost(p, r=r, arr=self.influence_grid) self.path = self.map_data.pathfind(start=self.p0, goal=self.p1, grid=self.influence_grid, sensitivity=self.sens, allow_diagonal=True) self.hero_tag = self.workers[0].tag diff --git a/run.py b/run.py index 935bcb64..112932e2 100644 --- a/run.py +++ b/run.py @@ -72,7 +72,7 @@ def get_map_file_list() -> List[str]: # for tup in influence_points: # p = tup[0] # r = tup[1] -# map_data.add_influence(p, r=r, arr=influence_grid) +# map_data.add_cost(p, r=r, arr=influence_grid) map_data.plot_influenced_path(start=p0, goal=p1, weight_array=influence_grid) map_data.show() # map_data.plot_map() @@ -107,7 +107,7 @@ def get_map_file_list() -> List[str]: # r = 7 + idx # # note that we use the default weight of 100, we could pass custom weights for each point though # for p in pts: -# arr = map_data.add_influence(p, r, arr) +# arr = map_data.add_cost(p, r, arr) # # """Plot path on weighted grid""" # map_data.plot_influenced_path(start=p0, goal=p1, weight_array=arr, diff --git a/tests/test_pathihng.py b/tests/test_pathihng.py index 777798d2..f8f89b22 100644 --- a/tests/test_pathihng.py +++ b/tests/test_pathihng.py @@ -102,7 +102,7 @@ def test_handle_illegal_values(self, map_data: MapData) -> None: arr = map_data.get_pyastar_grid() for p in pts: - arr = map_data.add_influence(p, r, arr) + arr = map_data.add_cost(p, r, arr) path = map_data.pathfind(p0, p1, grid=arr) assert (path is not None), f"path = {path}" @@ -138,6 +138,6 @@ def test_pathing_influence(self, map_data: MapData, caplog: LogCaptureFixture) - arr = map_data.get_pyastar_grid() for p in pts: - arr = map_data.add_influence(p, r, arr) + arr = map_data.add_cost(p, r, arr) path = map_data.pathfind(p0, p1, grid=arr) assert (path is not None) diff --git a/tmap.py b/tmap.py index 507a9399..0a0cadbd 100644 --- a/tmap.py +++ b/tmap.py @@ -59,7 +59,7 @@ def get_map_file_list() -> List[str]: arr = map_data.get_pyastar_grid() for p in pts: - arr = map_data.add_influence(p, r, arr) + arr = map_data.add_cost(p, r, arr) path = map_data.pathfind(p0, p1, grid=arr) map_data.plot_influenced_path(start=p0, goal=p1, weight_array=arr) map_data.show() @@ -69,12 +69,12 @@ def get_map_file_list() -> List[str]: # start = (110, 95) # goal = (110, 40) # grid = map_data.get_pyastar_grid() -# grid = map_data.add_influence((170, 140), r=20, arr=grid, weight=np.inf) +# grid = map_data.add_cost((170, 140), r=20, arr=grid, weight=np.inf) # resource_blockers = [Point2(m.position) for m in map_data.mineral_fields if "rich" in m.name.lower()] # for pos in resource_blockers: # radius = 1 # map_data.log(pos) -# grid = map_data.add_influence(p=pos, r=radius, arr=grid, weight=np.inf) +# grid = map_data.add_cost(p=pos, r=radius, arr=grid, weight=np.inf) # path = map_data.pathfind(start=start, goal=goal, grid=grid) # # map_data.plot_influenced_path(start=start, goal=goal, weight_array=grid)