Search code examples
algorithmpath-finding

Is there a pathing algorithm that instead of finding a path from point A to point B, it returns a path that covers the whole map?


I'm looking for a pathing algorithm that finds a path that instead of being the common A to B algorithm, it finds a path that covers the whole map (for example, snaking through shelves in a store)

I tried making one myself but it was extremely inefficient and didn't branch out very far.

Any ideas or resources I could use?


Solution

  • It's generally quite hard to find "reasonable" paths that visit all locations before ending up somewhere. The ideal path you'd like is called a Hamiltonian path and, unfortunately, no one knows how to find Hamiltonian paths efficiently in the general case. You'll probably need to either be content with weird paths that do a lot of retracing of steps or to accept paths that don't visit all locations before ending up at the destination.