Ejemplo n.º 1
0
    private void executeSearchAlgorithm()
    {
        if (debugExpandedNodes && search.GetRunning() && !search.Finished())
        {
            //GridMap.instance.ColorNodes(search.GetVisitedNodes(), agentColor);//jncor
            nodesExpanded = search.GetNumberOfNodesExpanded();
            nodesVisited  = search.GetNumberOfVisitedNodes();
            pathCost      = search.pathCost;
            uniText.text  = this.name + ": Searching... ";
            uniText.text += "expanded: " + nodesExpanded + " visited: " + nodesVisited;
        }

        if (search.Finished() && !algorithmFinished)
        {
            //uniText.text = this.name + ": Moving... ";
            nodesExpanded = search.GetNumberOfNodesExpanded();
            nodesVisited  = search.GetNumberOfVisitedNodes();
            pathCost      = search.pathCost;

            if (path == null)
            {
                if (search.FoundPath())
                {
                    path = search.RetracePath();
                    if (debugPath)
                    {
                        GridMap.instance.ColorNodes(path, agentColor);
                    }
                }
                else
                {
                    algorithmFinished = true;
                }
            }
            uniText.text = "D31 - Configuration Final Path Cost: " + TargetOptmisation.GetCost();
            string temp = "";
            foreach (GameObject obj in TargetOptmisation.GetBestSequenceFound())
            {
                temp += obj.name + ", ";
            }

            uniText.text += "\n" + temp;

            if (targets.Count > 0)
            {
                if (moveToNext)
                {
                    //// clear visited nodes
                    //if (debugExpandedNodes)
                    //{
                    //	GridMap.instance.ClearColorNodes(search.GetVisitedNodes());
                    //}
                    //move to next target
                    GridMap.instance.ClearColorNode(GridMap.instance.NodeFromWorldPoint(search.targetPos));
                    UpdateStartTargetPositions();
                    search.StartRunning();
                    path        = null;
                    currentCost = 0;
                    moveToNext  = false;
                    isAtTarget  = false;
                }
            }
        }
        if (!isMoving)
        {
            if (isAtTarget)
            {
                moveToNext = true;
            }
        }
    }