#"parent" will be added as a variable of each nodeclass finder(self): #just in case the variables need to be global def __init__(self): self.open = [] self.closed = [] self.current = startnode #startnode is determined by closest to AI self.path = []def calc_pathcost(end,start): #determines the cost of the pre-determined path between two points pathcost = 0 cur_node = end while cur_node != start: pathcost += dist(cur_node, cur_node.parent) #adds all the distances following the path so far cur_node = cur_node.parent return pathcostdef shortcut(node): #see if there is a better path to the current node from a node aleady in the closed list for neighbor in node.neighbors: if neighbor in f.closed: if dist(node,neighbor) < calc_pathcost(node,neighbor): node.parent = neighborf = finder() #instantiationwhile f.current != endnode: for neighbor in f.current.neighbors: deadend = 1 if neighbor not in f.closed: f.open.append(neighbor) deadend = 0 if deadend: f.current = f.current.parent for open_neighbor in f.open: Bestnode = the neighbor with the lowest f cost f.open.remove(Bestnode) f.closed.append(Bestnode) Bestnode.parent = f.current shortcut(Bestnode) f.current = Bestnodeif f.current == endnode: while f.current != startnode: f.path.append(f.current) f.current = f.current.parent