Esempio n. 1
0
    void MakeDead(Energies energy)
    {
        gameObject.GetComponent <Renderer> ().material.color = Color.black;
        uniText.text  = this.name + ": Dead... ";
        nodesExpanded = search.GetNumberOfNodesExpanded();
        ulong nodesOnList = search.GetMaxListSize();

        pathCost = search.pathCost;
        if (energy == Energies.Expanded)
        {
            uniText.text += "expanded: " + nodesExpanded + " >= " + search.maxNumberOfExpanded + "(maxNumberOfExpansions)";
        }
        else
        {
            uniText.text += "onlist: " + nodesOnList + " >= " + search.GetListSizeLimit() + "(GetListSizeLimit)";
        }
        TestWriter.writeResultLine(false, -1, search.numberOfVisited, search.numberOfExpandedNodes, search.maxListSize, search.currentState.depth, search.getExtra());
        TestSceneControl.ChangeScene();
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (!isDead)
        {
            if ((Input.GetKeyDown(KeyCode.Space) || autorun) && !agentRunning)
            {
                agentRunning = true;
                search.StartRunning();
                uniText      = GameObject.Find(GridMap.instance.prefixUiText + this.name).GetComponent <Text> ();
                uniText.text = this.name + ": Searching... ";
                //print (GridMap.instance.NodeFromWorldPoint(search.startPos));
            }

            if (debugExpandedNodes && search.GetRunning() && !search.Finished())
            {
                GridMap.instance.ColorNodes(search.GetVisitedNodes(), agentColor);
                nodesExpanded = search.GetNumberOfNodesExpanded();
                nodesVisited  = search.GetVisitedNodes().Count;
                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.GetVisitedNodes().Count;
                pathCost      = search.pathCost;
                uniText.text += "expanded: " + nodesExpanded + " visited: " + nodesVisited + " pathcost: " + pathCost;
                if (path == null)
                {
                    if (search.FoundPath())
                    {
                        path = search.RetracePath();
                        TestWriter.writeResultLine(search.FoundPath(), (int)search.Solution.f, search.numberOfVisited, search.numberOfExpandedNodes, search.maxListSize, search.currentState.depth, search.getExtra());
                        if (debugPath)
                        {
                            GridMap.instance.ColorNodes(path, agentColor);
                        }
                    }
                    else
                    {
                        algorithmFinished = true;
                    }
                }

                if (targets.Count > 0 && 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 (targets.Count == 0 && search.Finished() && search.FoundPath() && path != null)
                {
                    TestSceneControl.ChangeScene();
                }
            }
            if (!isMoving)
            {
                UpdateEnergy();
                if (isAtTarget && IsFullyLoaded())
                {
                    moveToNext = true;
                }
            }
        }
    }