Pathfinder

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.
Last edited on
Can you post can example that crashes?
Sure. It's just a map 25x25. Here http://pastebin.com/XHcMNvkp is full code.
I think crash can depends on RAM amount.
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.
Edit:

OK. I fixed it. It works great now. Thanks a lot. Here is full working code for other users: http://pastebin.com/NjwMmhx8
Last edited on
Topic archived. No new replies allowed.