Esempio n. 1
0
    private System.Collections.IEnumerator ProcessAllEdgesFromCurrent(PathRecord current, Vertex goalVertex)
    {
        foreach (Edge edge in current.node.edges)
        {
            PathRecord nextNode;
            float      nextNodeCostSoFar = current.costSoFar + edge.cost;
            float      nextNodeHeuristic;

            if (closeList.ContainsKey(edge.to))
            {
                nextNode = closeList[edge.to];
                if (nextNode.costSoFar <= nextNodeCostSoFar)
                {
                    continue;
                }
                nextNodeHeuristic = nextNode.heuristicValue;
                closeList.Remove(nextNode.node);
                #region Not a part of algorithm, visualization purposes only
                gridMarkerController.RemoveMarker(nextNode.node);
                #endregion
            }
            else if (openList.ContainsKey(edge.to))
            {
                nextNode = openList[edge.to];
                if (nextNode.costSoFar <= nextNodeCostSoFar)
                {
                    continue;
                }
                nextNodeHeuristic = nextNode.heuristicValue;
            }
            else
            {
                nextNode          = new PathRecord(edge.to);
                nextNodeHeuristic = heuristic.Estimate(nextNode.node.pos, goalVertex.pos);
            }

            nextNode.costSoFar      = nextNodeCostSoFar;
            nextNode.heuristicValue = nextNodeHeuristic;
            nextNode.connection     = new PathConnection(edge, current);
            if (!openList.ContainsKey(nextNode.node))
            {
                openList.Add(nextNode.node, nextNode);
                #region Not a part of algorithm, visualization purposes only
                gridMarkerController.PutOpenNodeMarker(nextNode.node);
                #endregion
            }
            yield return(new WaitForSecondsRealtime(sleepTime));
        }
    }