當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。