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)
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)