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)
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
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})