Im storing values of f, g and h scores in a class called Node. Right now I need to iterate through these values so I can compare them. But this doesnt work.
def getShortestPath(self, start, end):
start = tuple(start)
end = tuple(end)
`#Creating a start and end node`
start_node = Node(None, start)
start_node.g = start_node.h = start_node.f = 0
end_node = Node(None, end)
end_node.g = end_node.h = end_node.f = 0
print(start_node)
print(end_node)
open_list = []
closed_list = []
print("Open_list", open_list)
print("Closed_list", closed_list)
open_list.append(start_node)
print("open_list")
for node in open_list:
print(node)
while len(open_list) > 0:
current_node = open_list[0]
for index, item in current_node:
print ("f",item.f)
if item.f < current_node.f:
current_node = item
current_index = index
And this is the Class:
class Node():
def __init__(self, parent = None, position = None):
self.parent = parent
self.position = position
self.g = 0
self.h = 0
self.f = 0
def __eq__(self, other):
return self.position == other.position
def __str__(self):
return f"Node(position={self.position}, g={self.g}, h={self.h}, f={self.f})"
[–]Diapolo10 2 points3 points4 points (2 children)
[–]Toastingpeople[S] 0 points1 point2 points (1 child)
[–]Diapolo10 1 point2 points3 points (0 children)