I'm currently using the A* pathfinding algorithm to calculate a path on an infinite grid (using an UnboundedGrid in Gridworld, the AP CS case study, if that helps anyone). Everything works wonderfully, except for cases where no valid path exists because the end node is completely surrounded by walls. As expected, the algorithm continues searching infinitely, never finding the end node.
A possible solution to this would be to place invisible (as in, the user doesn't see them but the algorithm does) walls around the entire pathfinding area, making sure the start node, end node, and all the wall nodes are within these walls, with 2-3 spaces padding or so. Something like:
_________________________________
| |
| S | |
| _____| _____ |
| | E | |
| |___| |
|_______________________________|
...the idea being that eventually all the nodes will be added to the closedlist, the openlist will become empty, and at that point I'll know that no valid path exists.
Does this seem like a reasonable solution to the problem? Are there any ways in which this could potentially go wrong? I understand that another solution is to simultaneously pathfind backwards from the end, but this seems like it could be potentially expensive, particularly in cases where the end node isn't so tightly enclosed.