我目前正試圖在我的2D-sidescroller-procedurally generated世界遊戲(想像Terraria般的地形)中使用A *尋路。A *尋找一個2D Sidescroller
我一直在使用這種資源:http://www.redblobgames.com/pathfinding/a-star/introduction.html
並且已經主要利用給出以下僞代碼:
frontier = PriorityQueue()
frontier.put(start, 0)
came_from = {}
cost_so_far = {}
came_from[start] = None
cost_so_far[start] = 0
while not frontier.empty():
current = frontier.get()
if current == goal:
break
for next in graph.neighbors(current):
new_cost = cost_so_far[current] + graph.cost(current, next)
if next not in cost_so_far or new_cost < cost_so_far[next]:
cost_so_far[next] = new_cost
priority = new_cost + heuristic(goal, next)
frontier.put(next, priority)
came_from[next] = current
我的問題是:在2D-sidescroller的一個大程序上生成的世界,我該如何選擇邊界?通往特定瓦片的路徑可能距離任何距離,並且遍歷整個地圖顯然是不明智的。
我正試圖有效地做到這一點,所以任何援助將不勝感激!
如何知道將哪些節點放入打開列表中?它僅僅是直接的鄰居嗎?那麼對於一個2D sidescroller來說,它本質上是頂部,底部,左側和右側的節點? – Jestus 2014-12-03 01:47:31