closeList
选择最大的fCost的Node作为currentNode,并把currentNode从openList从openlist移除,并放入closeList中findPath过程
1.startTarget加入openlist,遍历openlist中fCost最小的Node作为currentNode(此时只有startNode) 2.将currentNode从openList中移除,并加入closeList 3.遍历出currentNode的neighbourNode,并计算neighbourNode的gCost和hCost,若gCost变小,则parent为currentNode,如果neighbourNode不在openList中,则将neighbourNode加入到openlist中,并且parent为currentNode。 4.查找openlist中fCost最小的Node,循环到步骤1重新开始 直到将targetNode添加入openList中,遍历结束。
路径:
targetNode targetNode.parent targetNode.parent.parent ... startNode距离计算
dis = 14y + 10( x - y )其中x,y为Node的下标总结
每个Node的parent都是从startNode到parent再到Node的距离最短每个current都是fCost最小,有同样的parent的Node到targetNode的距离也最短可以理解为每个Node到起点的距离最短,到终点的距离也最短,故总的距离最短