G-到起始点距离
H-到目标点距离
F=G+H
new openList;
new closeList;
openList.Add(start); //把起点加入开启列表
loop{
currentNode = lowest f cost in openList;//把开启列表中f值最低的节点作为当前节点
if (currentNode == end) return; //找到路线
foreach(neighbour in currentNode.Neighbours){ //对所有当前节点的相邻节点进行循环
if (closeList.Contains(neighbour) or neighbour == obstacle ) continue; //跳过关闭列表中的节点和障碍物节点
if( new fCost <= old fCost || !openList.Contains(neighbour) ){ //如果新节点的f值小于老节点的f值,用新节点替换老节点
neighbour.fCost = new fCost;
neighbour.parent = currentNode;
if(!openList.Contains(neighbour)) openList.Add(neighbour);//如果新节点不在开启列表,将其加入开启列表
}
}
}