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_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 mock_map_data(map_file: str) -> "MapData": from MapAnalyzer.MapData import MapData with lzma.open(f"{map_file}", "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) return MapData(bot=bot)
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_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_air_vs_ground(self, map_data: MapData) -> None: default_weight = 99 grid = map_data.get_air_vs_ground_grid(default_weight=default_weight) ramps = map_data.map_ramps path_array = map_data.path_arr.T for ramp in ramps: for point in ramp.points: if path_array[point.x][point.y] == 1: assert (grid[point.x][point.y] == default_weight)
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 'abys' in mf.lower(): # if 1==1: # mf = random.choice(map_files) # 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] # # for choke in map_data.map_chokes: # x, y = zip(*choke.corner_walloff) # plt.scatter(x, y) # # 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) # p0 = Point2((104, 153)) # p1 = Point2((107, 140)) # # influence_grid = map_data.get_clean_air_grid(default_weight=10) # influence_grid = map_data.get_pyastar_grid() # cost_point = (50, 130)
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}>")
def test_find_lowest_cost_points(self, map_data: MapData) -> None: cr = 7 safe_query_radius = 14 expected_max_distance = 2 * safe_query_radius influence_grid = map_data.get_air_vs_ground_grid() cost_point = (50, 130) influence_grid = map_data.add_cost(position=cost_point, radius=cr, grid=influence_grid) safe_points = map_data.find_lowest_cost_points( from_pos=cost_point, radius=safe_query_radius, grid=influence_grid) assert ( safe_points[0][0], np.integer ), f"safe_points[0][0] = {safe_points[0][0]}, type {type(safe_points[0][0])}" assert isinstance( safe_points[0][1], np.integer ), f"safe_points[0][1] = {safe_points[0][1]}, type {type(safe_points[0][1])}" cost = influence_grid[safe_points[0]] for p in safe_points: assert (influence_grid[ p] == cost), f"grid type = air_vs_ground_grid, p = {p}, " \ f"influence_grid[p] = {influence_grid[p]}, expected cost = {cost}" assert (map_data.distance(cost_point, p) < expected_max_distance) influence_grid = map_data.get_clean_air_grid() cost_point = (50, 130) influence_grid = map_data.add_cost(position=cost_point, radius=cr, grid=influence_grid) safe_points = map_data.find_lowest_cost_points( from_pos=cost_point, radius=safe_query_radius, grid=influence_grid) cost = influence_grid[safe_points[0]] for p in safe_points: assert (influence_grid[ p] == cost), f"grid type = clean_air_grid, p = {p}, " \ f"influence_grid[p] = {influence_grid[p]}, expected cost = {cost}" assert (map_data.distance(cost_point, p) < expected_max_distance) influence_grid = map_data.get_pyastar_grid() cost_point = (50, 130) influence_grid = map_data.add_cost(position=cost_point, radius=cr, grid=influence_grid) safe_points = map_data.find_lowest_cost_points( from_pos=cost_point, radius=safe_query_radius, grid=influence_grid) cost = influence_grid[safe_points[0]] for p in safe_points: assert (influence_grid[ p] == cost), f"grid type = pyastar_grid, p = {p}, " \ f"influence_grid[p] = {influence_grid[p]}, expected cost = {cost}" assert (map_data.distance(cost_point, p) < expected_max_distance) influence_grid = map_data.get_climber_grid() cost_point = (50, 130) influence_grid = map_data.add_cost(position=cost_point, radius=cr, grid=influence_grid) safe_points = map_data.find_lowest_cost_points( from_pos=cost_point, radius=safe_query_radius, grid=influence_grid) cost = influence_grid[safe_points[0]] for p in safe_points: assert (influence_grid[ p] == cost), f"grid type = climber_grid, p = {p}, " \ f"influence_grid[p] = {influence_grid[p]}, expected cost = {cost}" assert (map_data.distance(cost_point, p) < expected_max_distance)
li.append(os.path.join(map_files_folder, map_file)) return li map_files = get_map_file_list() map_file = "" for mf in map_files: if 'goldenwall' in mf.lower(): map_file = mf break with lzma.open(map_file, "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") map_data.plot_map() map_data.show() # map_data.save('fname') # TEST ILLEGAL VALUES ISOLATED base = map_data.bot.townhalls[0] reg_start = map_data.where(base.position_tuple) reg_end = map_data.where(map_data.bot.enemy_start_locations[0].position) 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))
map_files = os.listdir(map_files_folder) li = [] 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()