我目前正在试图实现在C++中使用A * A *寻路:http://www.policyalmanac.org/games/aStarTutorial.htm没有对角线移动
不过,对于第一个版本,我决定不包括对角线移动。
在C点的总结部分,在那里它循环检查当前点的邻居:
for each neighbour of the current square (above, below, left, right)
if neighbour on closed list or not walkable {
continue
}
if neighbour not in open list {
add to open list
set parent of neighbour to current square
update F, G, H values
} else if neighbour is on open list {
check to see if this path to that square is better,
using G cost as the measure. A lower G cost means that this is a better path.
If so, change the parent of the square to the current square,
and recalculate the G and F scores of the square.
}
如果我只允许4方向的运动,我仍然需要检查G值,看是否该广场的路径更好?例如,从起点开始,起点的所有4个邻居将具有相同的g。
如果我没有记错,所有的直接邻居都有相同的g成本,但是如果你的目标位于你所在位置的西北斜向,那么从西或北邻居开始的路径的g成本将低于g成本如果你是从东方或南方邻居开始的话。 – mrogers
@NicoSchertler那么我应该检查具有最低g成本的邻居吗?然后将该平方的父元素设置为当前平方并重新更新值? – PrimateJunkie
A *算法的步骤不会根据集合中的项目数量(当前单元格的邻居)而改变。你甚至可以在地图上有邻居清除的虫洞/传送器(除了相邻的单元格外),A *仍然可以工作。 –