// 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; } } } }
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; } } }