Beispiel #1
0
    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_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)
Beispiel #3
0
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
        #
        # print(np.unique(map_data.path_arr))
        # plt.imshow(map_data.path_arr, origin="lower")
        # plt.show()
        # plt.imshow(map_data.placement_arr, origin="lower")