Skip to content

Commit

Permalink
fix: air_vs_ground grid now accounts ramp points as pathable
Browse files Browse the repository at this point in the history
closed: #77
  • Loading branch information
eladyaniv01 committed Sep 6, 2020
1 parent 18a7c8a commit 99ad04d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions MapAnalyzer/Debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __call__(self, record: Dict[str, Any]) -> bool:
levelno = logger.level(self.level).no
return record["level"].no >= levelno


class MapAnalyzerDebugger:
"""
MapAnalyzerDebugger
Expand Down
2 changes: 1 addition & 1 deletion MapAnalyzer/Pather.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_clean_air_grid(self, default_weight: int = 1):
return np.where(clean_air_grid == 1, default_weight, 0)

def get_air_vs_ground_grid(self, default_weight: int):
grid = np.fmin(self.map_data.path_arr, self.map_data.placement_arr)
grid = np.fmax(self.map_data.path_arr, self.map_data.placement_arr)
air_vs_ground_grid = np.where(grid == 0, 1, default_weight).astype(np.float32)
return air_vs_ground_grid.T

Expand Down
21 changes: 20 additions & 1 deletion dummybot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from sc2.player import Bot, Computer
from sc2.position import Point3, Point2

import numpy as np

from MapAnalyzer import MapData

GREEN = Point3((0, 255, 0))
Expand Down Expand Up @@ -80,8 +82,25 @@ def _plot_influence(self, units):
pos = Point3((p.x, p.y, h))
self.client.debug_sphere_out(p=pos, r=r, color=RED)

def _draw_influence(self, grid: np.ndarray, threshold: int = 1) -> None:
from math import floor

def get_height(_x, _y) -> float:
return (
-16
+ 32 * self.game_info.terrain_height[(floor(_x), floor(_y))] / 255
)

for x, y in zip(*np.where(grid > threshold)):
pos: Point3 = Point3((x, y, get_height(x, y)))
val: float = grid[x, y]
color = (201, 168, 79)
self.client.debug_text_world(str(val), pos, color)

async def on_step(self, iteration: int):
# self.map_data.logger.info(iteration)
grid = self.map_data.get_air_vs_ground_grid()
self._draw_influence(grid=grid)
pass
# nonpathables = self.map_data.bot.structures
# nonpathables.extend(self.map_data.bot.enemy_structures)
Expand Down Expand Up @@ -163,7 +182,7 @@ def main():
map = "GoldenWallLE"
map = "AbyssalReefLE"
map = "SubmarineLE"
map = "aiarena_kingofthehill_1"
# map = "aiarena_kingofthehill_1"
sc2.run_game(
sc2.maps.get(map),
[Bot(sc2.Race.Terran, MATester()), Computer(sc2.Race.Zerg, sc2.Difficulty.VeryEasy)],
Expand Down
3 changes: 2 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ def get_map_file_list() -> List[str]:
reg_end = map_data.where_all(map_data.bot.enemy_start_locations[0].position)[0]
p0 = Point2(reg_start.center)
p1 = Point2(reg_end.center)
influence_grid = map_data.get_clean_air_grid()
influence_grid = map_data.get_air_vs_ground_grid()
map_data.plot_influenced_path(start=p0, goal=p1, weight_array=influence_grid, allow_diagonal=True)
map_data.show()
break
# if 'dream' in mf.lower():
# map_file = mf
# break
Expand Down

0 comments on commit 99ad04d

Please sign in to comment.