Pathfinding - A* with least turns

后端 未结 3 1999
清酒与你
清酒与你 2020-12-03 09:24

Is it possible to modify A* to return the shortest path with the least number of turns?

One complication: Nodes can no longer be distinguished solel

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 09:46

    If you really want to minimize the number of turns (as opposed to finding a nice tradeoff between turns and path length), why not transform your problem space by adding an edge for every pair of nodes connected by an unobstructed straight line; these are the pairs you can travel between without a turn. There are O(n) such edges per node, so the new graph is O(n3) in terms of edges. That makes A* solutions as much as O(n3) in terms of time.

    Manhattan distance might be a good heuristic for A*.

提交回复
热议问题