Exemplo n.º 1
0
    async def start(self, knowledge: 'Knowledge'):
        await super().start(knowledge)

        game_info: GameInfo = self.ai.game_info
        path_grid = game_info.pathing_grid
        placement_grid = game_info.placement_grid

        _data = [[0 for y in range(path_grid.height)]
                 for x in range(path_grid.width)]

        for x in range(0, path_grid.width):
            for y in range(0, path_grid.height):
                pathable = path_grid.is_set((x, y)) or placement_grid.is_set(
                    (x, y))
                if pathable:
                    _data[x][y] = 1

        self.path_finder_terrain = sc2pathlibp.PathFinder(_data)
        self.path_finder_ground = sc2pathlibp.PathFinder(_data)

        self.path_finder_terrain.normalize_influence(20)

        air_data = [[1 for y in range(path_grid.height)]
                    for x in range(path_grid.width)]
        for x in range(0, path_grid.width):
            for y in range(0, path_grid.height):
                if x < game_info.playable_area.x \
                        or x > game_info.playable_area.x + game_info.playable_area.width\
                        or y < game_info.playable_area.y \
                        or y > game_info.playable_area.y + game_info.playable_area.height:
                    air_data[x][y] = 0
        self.path_finder_air = sc2pathlibp.PathFinder(air_data)
Exemplo n.º 2
0
    async def start(self, knowledge: "Knowledge"):
        await super().start(knowledge)

        game_info: GameInfo = self.ai.game_info
        path_grid = game_info.pathing_grid
        placement_grid = game_info.placement_grid
        self.map = Sc2Map(
            path_grid.data_numpy,
            placement_grid.data_numpy,
            game_info.terrain_height.data_numpy,
            game_info.playable_area,
        )
        _data = [[0 for y in range(path_grid.height)]
                 for x in range(path_grid.width)]

        for x in range(0, path_grid.width):
            for y in range(0, path_grid.height):
                pathable = path_grid.is_set((x, y)) or placement_grid.is_set(
                    (x, y))
                if pathable:
                    _data[x][y] = 1

        self.path_finder_terrain = sc2pathlibp.PathFinder(_data)

        self.path_finder_terrain.normalize_influence(20)
Exemplo n.º 3
0
    async def start(self, knowledge: "Knowledge"):
        await super().start(knowledge)
        game_info: GameInfo = self.ai.game_info
        path_grid = game_info.pathing_grid
        placement_grid = game_info.placement_grid
        self.map = Sc2Map(
            path_grid.data_numpy,
            placement_grid.data_numpy,
            game_info.terrain_height.data_numpy,
            game_info.playable_area,
        )

        _data = np.fmax(path_grid.data_numpy, placement_grid.data_numpy).T
        self.path_finder_terrain = sc2pathlibp.PathFinder(_data)
        self.path_finder_terrain.normalize_influence(20)
Exemplo n.º 4
0
def read_maze(file_name: str) -> List[List[int]]:
    with open(file_name, "r") as text:
        m = text.read()
    lines = m.split("\n")
    final_maze = []
    for y in range(0, len(lines[0])):
        maze_line = []
        final_maze.append(maze_line)
        for x in range(0, len(lines)):
            maze_line.append(int(lines[x][y]))
    return final_maze


maze = read_maze("tests/maze4x4.txt")
pf = sc2pathlibp.PathFinder(maze)
print(pf.map)
print(pf.width)
print(pf.height)

print(pf.find_path((0, 0), (0, 2)))
pf.normalize_influence(100)
print(pf.lowest_influence_in_grid((2, 2), 5))
print(pf.find_path((0, 0), (0, 2)))

maze = read_maze("tests/AutomatonLE.txt")
pf = sc2pathlibp.PathFinder(maze)
pf.normalize_influence(10)

pf.heuristic_accuracy = 0
result = pf.find_path((32, 51), (150, 129))
Exemplo n.º 5
0
    async def find_wall_in_direction(
        self, center: Point2, perpendicular: Point2, search_vector: Point2, wall_finders: List[WallFinder]
    ):
        map_data = np.swapaxes(self.ai.game_info.pathing_grid.data_numpy, 0, 1)

        zone_height = self.ai.get_terrain_height(center)
        wall: Optional[Tuple[int, Point2, Point2, List[Point2]]] = None

        for i in range(5, 15):
            for j in range(-15, 16):
                lookup = center + search_vector * i + perpendicular * j

                if zone_height != self.ai.get_terrain_height(lookup):
                    # height doesn't match with zone height
                    continue

                for finder in wall_finders:

                    if finder.query(self.grid, lookup, ZoneArea.OwnNaturalZone):
                        pylon = lookup - 2.5 * search_vector
                        zealot = lookup + finder.zealot
                        gates = finder.positions(lookup)

                        tester: sc2pathlibp.PathFinder = sc2pathlibp.PathFinder(map_data)

                        tester.create_block(gates, (3, 3))
                        tester.create_block(zealot, (1, 1))
                        path = tester.find_path(
                            self.knowledge.expansion_zones[1].center_location, self.knowledge.enemy_start_location
                        )

                        if path[1] > 0:
                            self.print(
                                f"Wall {finder.name} was found at {lookup}, but disregarded due to not blocking check",
                                stats=False,
                            )
                            continue

                        if wall is None:
                            self.print(
                                f"Natural wall {finder.name} found! ({lookup})", stats=False, log_level=logging.DEBUG
                            )
                            wall = (finder.score, pylon, zealot, gates)
                        elif wall[0] < finder.score:
                            self.print(
                                f"Better natural wall {finder.name} found! ({lookup})",
                                stats=False,
                                log_level=logging.DEBUG,
                            )
                            wall = (finder.score, pylon, zealot, gates)
                        else:
                            self.print(
                                f"Natural wall {finder.name} found, but disregarded! ({lookup})",
                                stats=False,
                                log_level=logging.DEBUG,
                            )
                            wall = (finder.score, pylon, zealot, gates)

        if wall is not None:
            self.save_natural_wall(wall[1], wall[2], wall[3])
            return True
        return False