Skip to content

Commit

Permalink
fix: [#59](#59) clean air grid will now accept 'default_weight' argum…
Browse files Browse the repository at this point in the history
…ent (MapData, Pather)

Region will not auto show a plot,  following the convention of the project
  • Loading branch information
eladyaniv01 committed Aug 12, 2020
1 parent 50eb667 commit 355ab7d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions MapAnalyzer/MapData.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions MapAnalyzer/Pather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 7 additions & 5 deletions MapAnalyzer/Region.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -14,7 +17,7 @@ class Region:

def __init__(
self,
map_data: "MapData",
map_data: 'MapData',
array: np.ndarray,
label: int,
map_expansions: List[Point2],
Expand All @@ -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 = [
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 355ab7d

Please sign in to comment.