예제 #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_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_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}"
예제 #5
0
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))

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)
map_data.plot_influenced_path(start=p0, goal=p1, weight_array=arr)
map_data.show()
assert (path is not None), f"path = {path}"

# TEST MINERAL WALL ON GOLDENWALL ISOLATED
# start = (110, 95)
# goal = (110, 40)
# grid = map_data.get_pyastar_grid()
# grid = map_data.add_cost((170, 140), r=20, arr=grid, weight=np.inf)
# resource_blockers = [Point2(m.position) for m in map_data.mineral_fields if "rich" in m.name.lower()]
# for pos in resource_blockers:
# radius = 1
예제 #6
0
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")
        # plt.show()