Ejemplo n.º 1
0
    def _inspect_adjacent(self, node):
        pos = Point(node.x, node.y)
        for neighbor in self._adjacency_list(pos):
            new_g = node.g + pos.diagnol_distance(neighbor)

            if neighbor.blocks_move:
                continue

            self._searched_nodes.add(neighbor)
            if new_g < neighbor.g:
                # this path is better
                if neighbor in self._open:
                    # new path is better, take it out of open
                    self._open.remove(neighbor)
                    #self._open_set.discard(neighbor.coord)
                if neighbor.coord in self._closed_set:
                    self._closed_set.add(neighbor.coord)

            if neighbor not in self._open and \
               neighbor.coord not in self._closed_set:
                neighbor.g = new_g
                neighbor.h = self._heuristic(neighbor, self.target_node)
                neighbor.f = neighbor.g + neighbor.h
                neighbor.parent = node
                heapq.heappush(self._open, neighbor)
Ejemplo n.º 2
0
 def _heuristic(self, node_a, node_b):
     p_a = Point(node_a.x, node_a.y)
     return p_a.diagnol_distance(node_b)