コード例 #1
0
    /* --------------------------------------- List visual / Node representation ---------------------------------------
     * Some help functions for list visual
     */

    // Used by demo to update list visual (node/list representation)
    public void UpdateListVisual(string action, Node node, int index)
    {
        switch (action)
        {
        case UtilGraph.ADD_NODE: listVisual.AddListObject(node); break;

        case UtilGraph.PRIORITY_ADD_NODE: listVisual.PriorityAdd(node, index); break;

        case UtilGraph.REMOVE_CURRENT_NODE: listVisual.RemoveCurrentNode(); break;

        case UtilGraph.DESTROY_CURRENT_NODE: listVisual.DestroyCurrentNode(); break;
        }
    }
コード例 #2
0
    // Backtracks the path from input node
    public IEnumerator BacktrackShortestPath(Node node, WaitForSeconds demoStepDuration)
    {
        // Start backtracking from end node back to start node
        while (node != null)
        {
            // Node representation
            listVisual.RemoveCurrentNode();
            yield return(demoStepDuration);

            // Change color of node
            node.CurrentColor = UtilGraph.SHORTEST_PATH_COLOR;

            // Change color of edge leading to previous node
            Edge backtrackEdge = node.PrevEdge;

            if (backtrackEdge == null)
            {
                break;
            }

            backtrackEdge.CurrentColor = UtilGraph.SHORTEST_PATH_COLOR;

            // Set "next" node
            if (backtrackEdge is DirectedEdge)
            {
                ((DirectedEdge)backtrackEdge).PathBothWaysActive = true;
            }

            node = backtrackEdge.OtherNodeConnected(node);

            if (backtrackEdge is DirectedEdge)
            {
                ((DirectedEdge)backtrackEdge).PathBothWaysActive = false; // incase using same graph again at some point
            }
            yield return(demoStepDuration);

            listVisual.DestroyCurrentNode();

            yield return(demoStepDuration);
        }
    }