Problem:
Modify the A* algorithm we optimized for fewer turns. The algorithm will now find a path from (a,b) to ANY TILE ADJACENT TO (x,y), where (x+1,y) or (x-1,y) are favored when possible.
My attempted solution:
- Run the original A* algorithm from (a,b) to (x,y).
- Find the last coordinate in the path that travels through (x-1,) or (x+1,) if any.
- If there is a straight accessible vertical line from * to y in that coordinate plane, amend the path to follow that line.
Visual Demonstration: (path from S to E where X is inaccessible)
......S .....S
. X . X
. => .
. .
E E.
However I'm not sure that my solution would work in some cases, ie:
......S .....S
. X . X
.X ??? X.
. .
E E..
Can anyone think of a solution to this problem?
Note: The A* algorithm is generic other than factoring in the number of direction changes to favor less turns in the resulting path.