I am trying to make the enemy node follow the node player in C # with the A * algorithm. I read the tutorials and downloaded some C # examples. Now I have an A * algorithm. It will follow the player in open space, but will fall into the trap when trying to trace around an object.
So, when my algorithm checks and moves in the direction of the smallest value of F, it may run into a dead end, and at that moment it needs to repeat steps backwards, but this is not possible, because my code says that the previously checked node is closed and cannot be moved and so he is stuck.
How to recalculate a closed node to tell my algorithm that it is normal to go back.
In addition, if I say that my algorithm returns to itself, then that should prevent it from returning to a better node, it has just appeared; effectively returning between two nodes repeatedly.
I see that it should be able to check the node in a closed list and determine if it is better on this particular path, but I'm not sure how to do it.
Heuristics that I use.
G = Math.Abs(StartNodeX - TargetNodeX) + Math.Abs(StartNodeY - TargetNodeY)
H = Math.Abs(CurrentNodeX - TargetNodeX) + Math.Abs(CurrentNodeY - CurrentNodeY)
F = G + H
Psuedocode
- Add all adjacent nodes to the Open list.
- Check all these nodes for the smallest value of F and add that node to the list of best path
- Add all checked nodes to the closed list (all of them have been checked, do not want to check them again)
- Repeat until you reach your goal.
- Move enemy 1 node towards the best path
- Repeat again and again
source
share