private void AddToOpenList(NavigationNode _node, NavigationNode _parent, int _parentStartCost, NavigationNode _goalNode) { //first, calculate estimated distance from goal in 'steps'. float distance = Vector3.Distance(_node.WorldPosition, _goalNode.WorldPosition); //add the node plus it's accompanying info into the dictionary. OpenNodeInformation info = new OpenNodeInformation(_node, _parent, _parentStartCost); info.EstimatedDestinationCost = distance; m_openNodeList.Add(_node, info); }
private NavigationNode SelectBestOpenCandidate() { //iterate through the current open node list. NavigationNode bestNode = null; int currentBestScore = Int32.MaxValue; //arbitrarily high. foreach (NavigationNode node in m_openNodeList.Keys) { if (m_closedNodeList.Contains(node)) { continue; } OpenNodeInformation info = m_openNodeList[node]; int nodeScore = info.StartCost + (int)info.EstimatedDestinationCost; nodeScore += (int)node.Cost; if (nodeScore < currentBestScore) { bestNode = node; currentBestScore = nodeScore; } } return(bestNode); }