diff --git a/MapAnalyzer/Debugger.py b/MapAnalyzer/Debugger.py index a61c5d9d..054e9f70 100644 --- a/MapAnalyzer/Debugger.py +++ b/MapAnalyzer/Debugger.py @@ -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 diff --git a/MapAnalyzer/Pather.py b/MapAnalyzer/Pather.py index 5a0f838b..05c9ff83 100644 --- a/MapAnalyzer/Pather.py +++ b/MapAnalyzer/Pather.py @@ -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 diff --git a/dummybot.py b/dummybot.py index 8756ab31..4e940c7d 100644 --- a/dummybot.py +++ b/dummybot.py @@ -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)) @@ -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) @@ -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)], diff --git a/run.py b/run.py index b86cadc1..e626c6b6 100644 --- a/run.py +++ b/run.py @@ -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