public CPathAStar() { // Make all the nodes that we will use, and put them on the unused list for (uint i = 0; i < MAX_NODES; i++) { CAStarNode pNewNode = new CAStarNode(); pNewNode.SetpNext(m_UnusedNodes.GetpNext()); m_UnusedNodes.SetpNext(pNewNode); } }
void AddToOpenList(CAStarNode pNewNode) { CAStarNode pParentNode = m_OpenNodes; CAStarNode pNodeToCheck = m_OpenNodes.GetpNext(); while (pNodeToCheck != null) { if (pNewNode.GetTotalCostF() < pNodeToCheck.GetTotalCostF()) { pParentNode.SetpNext(pNewNode); pNewNode.SetpNext(pNodeToCheck); return; } pParentNode = pNodeToCheck; pNodeToCheck = pNodeToCheck.GetpNext(); } // it is the worst one in the list put it at the end //assert(pParentNode.GetpNext() == null); pParentNode.SetpNext(pNewNode); //assert(pNewNode.GetpNext() == null); }
void RemoveFromOpenList(CAStarNode pNodeToRemove) { CAStarNode pParentNode = m_OpenNodes; CAStarNode pNodeToCheck = m_OpenNodes.GetpNext(); while (pNodeToCheck != null) { if (pNodeToRemove == pNodeToCheck) { pParentNode.SetpNext(pNodeToCheck.GetpNext()); pNodeToCheck.SetpNext(null); return; } pParentNode = pNodeToCheck; pNodeToCheck = pNodeToCheck.GetpNext(); } //assert(0); // why are trying to remove an item that is not in the list }
void ReturnAllNodesToUnusedList(CAStarNode pParentOfUnusedNode) { //AssertNoLostNodes(); CAStarNode pFirstNodeToReturn = pParentOfUnusedNode.GetpNext(); if (pFirstNodeToReturn != null) { CAStarNode pLastNodeToReturn = pFirstNodeToReturn; // if the unused list has stuff in it already if (m_UnusedNodes.GetpNext()) { // find the last node we want to return while (pLastNodeToReturn.GetpNext()) { pLastNodeToReturn = pLastNodeToReturn.GetpNext(); } // set the last node to return next to the first node of the unused list pLastNodeToReturn.SetpNext(m_UnusedNodes.GetpNext()); // set the first node of the unused list to the first node to return m_UnusedNodes.SetpNext(pFirstNodeToReturn); // make sure the list we took them from doesn't still have them pParentOfUnusedNode.SetpNext(null); //AssertNoLostNodes; } else { // just put it on the unused list m_UnusedNodes.SetpNext(pFirstNodeToReturn); pParentOfUnusedNode.SetpNext(null); //AssertNoLostNodes; } } //AssertNoLostNodes; }
void AddNodeToClosedList(CAStarNode pNodeToClose) { RemoveFromOpenList(pNodeToClose); //assert(pNodeToClose.GetpNext() == null); // it should be in no list when you add it to the clossed pNodeToClose.SetpNext(m_ClosedNodes.GetpNext()); m_ClosedNodes.SetpNext(pNodeToClose); //AssertNoLostNodes; }