Here's an example image:
The blue tile at the top is the starting location and the blue tile at the bottom is the goal location. The green path is the path found between the two.
Astar doesn't seem to work well for this because I don't want the shortest path, but rather an L-shaped path. That is, the minimum edge length should always be 5, and it should look to minimize turns.
My current idea is something along these lines, but I'm not sure if it's ideal or if it will really work:
- Move straight 5 tiles
- Calculate the vector from the current location to the goal location
- If, for example, the direction is mostly south, then travel straight south.
- Every tile after 5 tiles straight, evaluate again which direction we should head.
- If we decide to change directions, then continue in that direction for at least another 5 tiles until checking again
And then pretty much repeat steps 4 and 5 on loop until we're at the goal location.
It's okay for the pathfinding to sometimes fail if a path cannot be made, or for it to fail if the path exceeds a certain length. The above approach was the first thing that came to mind, but I'm not sure if it's ideal, or if it would even work without sometimes encountering an infinite loop condition where the path keeps going back and forth by getting stuck.