I’m currently working on my second parthfinding routine (the first one, Breadth, didn’t work out for me)
Sebastian Lague has a great tutorial on this and I’m building my script using his explanation of the process.
Now I’m at the optimisation part of the tutorial, I understand the ‘heap’ principle. Why it is nescesary to decrease searching through the ‘openList’.
Using open areas with obstacles or narrow corridors (in my case) your path mosly leads in straight lines, no deviation. The ‘openList’ gets bigger and bigger, collecting new nodes storing the old ones from several iterations back who will probably never get used. (… probably). Making it harder and harder to loop through the openList.
But I started thinking.
For example. If you start out with a fCost of 200, there will never be an fCost lower than 200 because 200 is the shortes route. So when you search for neighbouring nodes and find another node with fCost 200 this is obviously the right path to take.
Why not add a ‘preferedList’. If the current node finds a neighbor (or multiple) with the same fCost there will not be any other better nodes in the openList because you are already working with the lowest fCost. The open List only contains of higher fCost nodes stored in it.
Higher fCost found in neigbours are stored in the openList, same fCost are stored in the ‘preferedList’.
If the ‘preferredList’ is empty, search through the openList for a (or multiple) nodes with the lowest fCost and repopulate the ‘preferredList’.
If the node finds a lower fCost node, move all nodes from preferredList to openList, put the new found lowest fCost node in the ‘preferredList’ and continue the routine.
Any thoughts?