Skip to content

Commit

Permalink
Merge pull request #146 from eladyaniv01/develop
Browse files Browse the repository at this point in the history
Pre Release
  • Loading branch information
eladyaniv01 authored Feb 3, 2021
2 parents da7fa7a + 4c846aa commit 167ada1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions MapAnalyzer/Pather.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ def add_cost(position: Tuple[float, float], radius: float, arr: ndarray, weight:
arr[disk] = np.where(arr[disk] == 1, initial_default_weights, arr[disk])

arr[disk] += weight
if safe and np.any(arr < 1):
if safe and np.any(arr[disk] < 1):
logger.warning(
"You are attempting to set weights that are below 1. falling back to the minimum (1)")
arr = np.where(arr[disk] < 1, 1, arr[disk])
arr[disk] = np.where(arr[disk] < 1, 1, arr[disk])

return arr
27 changes: 23 additions & 4 deletions tests/test_pathihng.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os

import numpy as np
from _pytest.logging import LogCaptureFixture
from _pytest.python import Metafunc
from sc2.position import Point2

from MapAnalyzer import Region
from MapAnalyzer.MapData import MapData
from MapAnalyzer.destructibles import *
from MapAnalyzer.utils import get_map_files_folder, mock_map_data, get_map_file_list
from MapAnalyzer.MapData import MapData
from MapAnalyzer.utils import get_map_file_list, get_map_files_folder, mock_map_data
from tests.mocksetup import get_map_datas, get_random_point, logger
import numpy as np

logger = logger

Expand Down Expand Up @@ -134,7 +134,7 @@ def test_region_connectivity(self, map_data: MapData) -> None:
not_through=[destination])
assert (bad_request == [])

def test_handle_illegal_values(self, map_data: MapData) -> None:
def test_handle_out_of_bounds_values(self, map_data: MapData) -> None:
base = map_data.bot.townhalls[0]
reg_start = map_data.where_all(base.position_tuple)[0]
assert (isinstance(reg_start,
Expand All @@ -153,6 +153,25 @@ def test_handle_illegal_values(self, map_data: MapData) -> None:
path = map_data.pathfind(p0, p1, grid=arr)
assert (path is not None), f"path = {path}"

def test_handle_illegal_weights(self, map_data: MapData) -> None:
base = map_data.bot.townhalls[0]
reg_start = map_data.where_all(base.position_tuple)[0]
assert (isinstance(reg_start,
Region)), f"reg_start = {reg_start}, base = {base}, position_tuple = {base.position_tuple}"
reg_end = map_data.where_all(map_data.bot.enemy_start_locations[0].position)[0]
p0 = reg_start.center
p1 = reg_end.center
pts = []
r = 10
for i in range(10):
pts.append(get_random_point(20, 180, 20, 180))

arr = map_data.get_pyastar_grid()
for p in pts:
arr = map_data.add_cost(p, r, arr, weight=-100)
path = map_data.pathfind(p0, p1, grid=arr)
assert (path is not None), f"path = {path}"

def test_find_lowest_cost_points(self, map_data: MapData) -> None:
cr = 7
safe_query_radius = 14
Expand Down

0 comments on commit 167ada1

Please sign in to comment.