Original Post
Ok, so I'm making a pathfinder in VB. I'm having trouble finding complex paths (that do exist) and getting the shortest path to them (sometimes my pathfinder will make unnecessary trips). I think the problem is in the code where I search in four directions. Maybe I didn't understand what to do correctly, but here is what I am doing... I think the problem comes when I check if a node lying on a different path has a lower g value then the one already on the open list. But I've seen many articles using many different ways of accomplishing this. I don't want anything fancy yet, just to make sure that it finds any path that exists. Maybe someone could just tell me in pseudocode what to do in the direction search. By the way thanks!
'Move in the direction we seek
tmpNode.x = curNode.x - 1
tmpNode.y = curNode.y
'Determine if this tile is walkable
If lngMap(tmpNode.x, tmpNode.y) = 0 Then
'Determine if this node is on the closed list
If Not clsClosed.MemberOf(tmpNode) Then
If Not clsOpen.MemberOf(tmpNode) Then
'Update the parents
tmpNode.parentx = curNode.x
tmpNode.parenty = curNode.y
'Update the heuristics
tmpNode.g = curNode.g + 10
tmpNode.h = (Abs(tmpNode.x - nGoal.x) + Abs(tmpNode.y - nGoal.y)) * 10
tmpNode.f = tmpNode.g + tmpNode.h
'Add the node to the open list
clsOpen.Add tmpNode
Else
'Set them equal
tmpNode2 = tmpNode
'Update the parents
tmpNode2.parentx = curNode.x
tmpNode2.parenty = curNode.y
'Update the heuristics
tmpNode2.g = curNode.g + 10
tmpNode2.f = tmpNode.g + tmpNode.h
'Determine if this is a better route
If tmpNode2.g < clsOpen.GetData(tmpNode).g Then
clsOpen.SetData tmpNode2, tmpNode
'Sort the list to make up for the changes
clsOpen.Sort
End If
End If
End If
End If