当前位置: 首页>>代码示例>>Python>>正文


Python Region.remove方法代码示例

本文整理汇总了Python中region.Region.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Region.remove方法的具体用法?Python Region.remove怎么用?Python Region.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在region.Region的用法示例。


在下文中一共展示了Region.remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_path

# 需要导入模块: from region import Region [as 别名]
# 或者: from region.Region import remove [as 别名]
    def find_path(self, loc1, loc2, pid=None, cPane=None):
        '''
        Pathfinding algorithm using a tweaked implementation of Dijkstra's Algorithm
        The difference is that we may not need a path directly to loc2.  If pid refers to a valid
        Person object, we just need a path to the closest location that is within attack range of
        the final target.  So loop through all possible locations searching for the location with the
        shortest path, and return that.
        '''
        if loc1 == loc2:
            return []
        if loc1.distance(loc2) == 1:
            return [loc2]

        Q = Region("SQUARE", Location(loc1.pane, (0, 0)), Location(loc1.pane, (PANE_X - 1, PANE_Y - 1))).locations
        dist = {}
        prev = {}
        q = PriorityQueue()
        for v in Q:
            dist[v] = float('inf')
            prev[v] = None

        dist[loc1] = 0
        q.put((0, loc1))

        while not q.empty():
            u = q.get()[1]
            if u == loc2 or dist[u] == float('inf'):
                break

            neighbors = [u.move(dir) for dir in [2, 4, 6, 8]]
            neighbors = [v for v in neighbors if v in Q and (self.tile_is_open(v, pid, cPane) or v == loc2)]
            for v in neighbors:
                Q.remove(v)
                alt = dist[u] + u.distance(v)
                if alt < dist[v]:
                    dist[v] = alt
                    prev[v] = u
                    q.put((dist[v], v))

        path = []
        u = loc2

        # Update destination to a location within attack range of the ultimate target
        if pid:
            minDist = (dist[u], u)
            for loc in [l for l in Region("DIAMOND", u, self.person[pid].attackRange - 1) if l.pane == loc1.pane]:
                if prev[loc] and dist[loc] < minDist[0]:
                    minDist = (dist[loc], loc)
            u = minDist[1]

        # If still no valid destination, find the closest point in anticipation of an obstacle
        # eventually being removed, such as an ally getting killed
        radius = 1
        while not prev[u] and radius < 10:
            R = Region("SQUARE", loc2, radius) - Region("SQUARE", loc2, radius - 1)
            for loc in [l for l in R if l.pane == loc1.pane]:
                if prev[loc]:
                    u = loc
                    break
            radius += 1

        # Follow the path backwards from destination to reconstitute the shortest path
        while prev[u]:
            path.append(u)
            u = prev[u]

        path.reverse()
        return path
开发者ID:akintu,项目名称:akintu,代码行数:70,代码来源:server.py


注:本文中的region.Region.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。