Ejemplo n.º 1
0
        //given a node index and two lists that COULD contain it, return the node from ONE of them
        private static Node GetNodeFromLists(NodeIndex nIndex, List <Node> list1, List <Node> list2)
        {
            if (nIndex == null)
            {
                return(null);
            }
            if (list1 == null && list2 == null)
            {
                return(null);
            }

            if (list1.Count > 0 && nIndex.GetParentIndex() == list1[0].index.GetParentIndex())
            {
                if (list1.Count <= nIndex.GetLowestIndex())
                {
                    return(null);
                }
                return(list1[nIndex.GetLowestIndex()]);
            }
            if (list2.Count > 0 && nIndex.GetParentIndex() == list2[0].index.GetParentIndex())
            {
                if (list2.Count <= nIndex.GetLowestIndex())
                {
                    return(null);
                }
                return(list2[nIndex.GetLowestIndex()]);
            }

            return(null);
        }
Ejemplo n.º 2
0
        //return the list of nodes that the path consists of
        private static List <NodeIndex> RetracePath(Node destNode, List <Node> finalNodeList)
        {
            List <NodeIndex> finalPath = new List <NodeIndex>();
            NodeIndex        index     = destNode.index;

            finalPath.Add(index);
            index = destNode.previousNode;

            if (index == null)
            {
                return(finalPath);
            }
            while (finalNodeList[index.GetLowestIndex()].previousNode != null)
            {
                finalPath.Add(index);
                finalNodeList[index.GetLowestIndex()].accumulatedCost = 0;

                index = finalNodeList[index.GetLowestIndex()].previousNode;
            }
            finalNodeList[index.GetLowestIndex()].accumulatedCost = 0;

            finalPath.Add(index);
            finalPath.Reverse();

            return(finalPath);
        }