Problem:
Change the A * algorithm we optimized for fewer turns. Now the algorithm will find the path from (a, b) to ANY SURFACE TO (x, y), where (x + 1, y) or (x-1, y) is preferable when possible.
My decision:
- Run the original A * algorithm from (a, b) to (x, y).
- Find the last coordinate in the path passing through (x-1,) or (x + 1,), if any.
- If there is a straight vertical line available from * to y in this coordinate plane, change the path following this line.
Visual demo: (path from S to E, where X is not available)
......S .....S
. X . X
. => .
. .
E E.
However, I am not sure that my solution will work in some cases, for example:
......S .....S
. X . X
.X ??? X.
. .
E E..
Can anyone think of a solution to this problem?
. A * , , .