コード例 #1
0
ファイル: HikingMap.py プロジェクト: LukasB97/Math
 def _get_unvisited_neighbors(self, x, y):
     to_open = Fheap()
     if y > 1 and self.nodes[(x, y - 1)].state == NodeState.UNKNOWN:
         to_open.insert(self.nodes[(x, y - 1)])
     if x < self.col_count and self.nodes[(x + 1,
                                           y)].state == NodeState.UNKNOWN:
         to_open.insert(self.nodes[(x + 1, y)])
     if y < self.row_count and self.nodes[(x, y +
                                           1)].state == NodeState.UNKNOWN:
         to_open.insert(self.nodes[(x, y + 1)])
     if x > 1 and self.nodes[(x - 1, y)].state == NodeState.UNKNOWN:
         to_open.insert(self.nodes[(x - 1, y)])
     return to_open
コード例 #2
0
ファイル: HikingMap.py プロジェクト: LukasB97/Math
 def start(self, from_x, from_y, to_x, to_y):
     open_nodes = Fheap()
     self._close_node(from_x, from_y, open_nodes)
     target = self.nodes[(to_x, to_y)]
     closed_node = self._next_step(open_nodes)
     while closed_node != target:
         closed_node = self._next_step(open_nodes)
コード例 #3
0
    if check(((x + 1, y + 1))):
        adj.append(((x + 1, y + 1)))
    if check(((x + 1, y - 1))):
        adj.append(((x + 1, y - 1)))

    if check(((x - 1, y))):
        adj.append(((x - 1, y)))
    if check(((x - 1, y + 1))):
        adj.append(((x - 1, y + 1)))
    if check(((x - 1, y - 1))):
        adj.append(((x - 1, y - 1)))

    return adj


queue = Fheap()

node_dict = {}

for y in range(n):
    for x in range(m):
        if y == source[1] and x == source[0]:
            node = Node(destination[1], destination[0], x, y, 0, option)
            node.val = 0
            queue.insert(node)
            node_dict.update({(x, y): node})

        elif maze[y][x] != 0:
            node = Node(destination[1], destination[0], x, y, infinity, option)
            queue.insert(node)
            node_dict.update({(x, y): node})
コード例 #4
0
ファイル: HikingMap.py プロジェクト: LukasB97/Math
 def _next_step(self, open_nodes: Fheap):
     to_close = open_nodes.extract_min()
     self._close_node(to_close.x, to_close.y, open_nodes)
     return to_close
コード例 #5
0
ファイル: HikingMap.py プロジェクト: LukasB97/Math
 def _close_node(self, x, y, open_nodes: Fheap, finished=False):
     self.nodes[(x, y)].state = NodeState.PATH
     if not finished:
         neighbors = self._get_unvisited_neighbors(x, y)
         open_nodes.union(neighbors)