Hey guys,
So I’ve made an implementation of an A* algorithm for my AI class, and the algo runs blazingly* fast, it has no trouble founding a path in a 256*256 grid, however the reconstructPath method I’ve made is slow and subject to run out of heap space.
So the question is, how the heck can I improve this piece of code:
private static List<Node> reconstructPath(Node start, Node goal) {
List<Node> path = new ArrayList<>();
start.came_from = null; // Reset the came_from
Node current = goal;
while(current != null) {
path.add(current);
current = current.came_from;
}
return path;
}
- That’s my claim, and I’m sticking with it!