def test_region_connectivity(self, map_data: MapData) -> None: base = map_data.bot.townhalls[0] region = map_data.where_all(base.position_tuple)[0] destination = map_data.where_all(map_data.bot.enemy_start_locations[0].position)[0] all_possible_paths = map_data.region_connectivity_all_paths(start_region=region, goal_region=destination) for p in all_possible_paths: assert (destination in p), f"destination = {destination}" bad_request = map_data.region_connectivity_all_paths(start_region=region, goal_region=destination, not_through=[destination]) assert (bad_request == [])
def test_sensitivity(self, map_data: MapData) -> None: base = map_data.bot.townhalls[0] reg_start = map_data.where_all(base.position_tuple)[0] reg_end = map_data.where_all(map_data.bot.enemy_start_locations[0].position)[0] p0 = reg_start.center p1 = reg_end.center arr = map_data.get_pyastar_grid() path_pure = map_data.pathfind(p0, p1, grid=arr) path_sensitive_5 = map_data.pathfind(p0, p1, grid=arr, sensitivity=5) path_sensitive_1 = map_data.pathfind(p0, p1, grid=arr, sensitivity=1) assert (len(path_sensitive_5) < len(path_pure)) assert (p in path_pure for p in path_sensitive_5) assert (path_sensitive_1 == path_pure)
def test_clean_air_grid_smoothing(self, map_data: MapData) -> None: default_weight = 2 base = map_data.bot.townhalls[0] reg_start = map_data.where_all(base.position_tuple)[0] 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) grid = map_data.get_clean_air_grid(default_weight=default_weight) cost_points = [(87, 76), (108, 64), (97, 53)] cost_points = list(map(Point2, cost_points)) for cost_point in cost_points: grid = map_data.add_cost(position=cost_point, radius=7, grid=grid) path = map_data.pathfind(start=p0, goal=p1, grid=grid, smoothing=True) assert (len(path) < 50)
def test_vision_blockers(self, map_data: MapData) -> None: all_chokes = map_data.map_chokes for vb in map_data.map_vision_blockers: assert (vb in all_chokes) for p in vb.points: assert (vb in map_data.where_all(p)), \ logger.error(f"<Map : {map_data}, Choke : {vb}," f" where_all : {map_data.where_all(vb.center)} point : {vb.center}>")
def test_regions(self, map_data: MapData) -> None: for region in map_data.regions.values(): for p in region.points: assert (region in map_data.where_all(p)), f"expected {region}, got {map_data.where_all(p)}, point {p}" assert (region == map_data.where(region.center)) # coverage region.plot(testing=True)
def test_chokes(self, map_data: MapData) -> None: for choke in map_data.map_chokes: for p in choke.points: assert (choke in map_data.where_all(p)), \ logger.error(f"<Map : {map_data}, Choke : {choke}," f" where : {map_data.where(choke.center)} point : {choke.center}>") assert (choke.side_a in choke.points), f"Choke {choke}, side a {choke.side_a} is not in choke points" assert (choke.side_b in choke.points), f"Choke {choke}, side b {choke.side_b} is not in choke points"
def test_pathing_influence(self, map_data: MapData, caplog: LogCaptureFixture) -> None: logger.info(map_data) base = map_data.bot.townhalls[0] reg_start = map_data.where_all(base.position_tuple)[0] 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(50): pts.append(get_random_point(0, 200, 0, 200)) arr = map_data.get_pyastar_grid() for p in pts: arr = map_data.add_cost(p, r, arr) path = map_data.pathfind(p0, p1, grid=arr) assert (path is not None)
def test_handle_illegal_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, 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(50): pts.append(get_random_point(-500, -250, -500, -250)) arr = map_data.get_pyastar_grid() for p in pts: arr = map_data.add_cost(p, r, arr) path = map_data.pathfind(p0, p1, grid=arr) assert (path is not None), f"path = {path}"
def test_chokes(self, map_data: MapData) -> None: for choke in map_data.map_chokes: for p in choke.points: assert (choke in map_data.where_all(p)), \ logger.error(f"<Map : {map_data}, Choke : {choke}," f" where : {map_data.where(choke.center)} point : {choke.center}>")
for map_file in map_files: li.append(os.path.join(map_files_folder, map_file)) return li map_files = get_map_file_list() for mf in map_files: if 'death' in mf.lower(): # if 'abys' in mf.lower(): with lzma.open(mf, "rb") as f: raw_game_data, raw_game_info, raw_observation = pickle.load(f) bot = import_bot_instance(raw_game_data, raw_game_info, raw_observation) map_data = MapData(bot, loglevel="DEBUG") base = map_data.bot.townhalls[0] reg_start = map_data.where_all(base.position_tuple)[0] 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_air_vs_ground_grid(default_weight=50) influence_grid = map_data.get_pyastar_grid() # p = (50, 130) # influence_grid = map_data.add_cost(grid=influence_grid, position=p, radius=10, initial_default_weights=50) map_data.plot_influenced_path(start=p0, goal=p1, weight_array=influence_grid, allow_diagonal=False) map_data.show() # import matplotlib.pyplot as plt # import numpy as np