Hello,
I've been working on some project. I would like to create a simple pathfinder.
I use binary tile map. Diagonal movements aren't allowed, step cost is always 1 and there can be many goals (or no goal).
I'm using code from http://coliru.stacked-crooked.com/a/cedb4a0af0360dd1 . It works great with map 10x10. However when I set map size to 25x25 and goals are very far from start position or there aren't goals program crashes due to using too much memory. What should I change? I need this code to even 100x100 maps.
There are two problems:
1. found should be cleared before iterating over candidates, just like candidates is cleared before iterating over found.
2. You need to set cand->second.visited to true immediate after checking if it's true, not in the candidates ranged for, otherwise the number of candidates increases by a trinary exponent each time through the while loop.