/// <summary> /// Changes the current node to be the parent of the current node, if it has a parent /// </summary> public void SelectParentNode() { if (CurrentNode.Parent != null) { CurrentNode = (NodeObject)CurrentNode.Parent; LineDraw.SelectNode(CurrentNode); TreeUIController.DisplayNodeInfo(CurrentNode); } }
/// <summary> /// Changes the currently selected node to be a child of the currently selected node /// </summary> /// <param name="childIndex">The child index of the new selected node</param> public void SelectChildNode(int childIndex) { if (CurrentNode.Children.Count > childIndex) { CurrentNode = (NodeObject)CurrentNode.Children[childIndex]; LineDraw.SelectNode(CurrentNode); TreeUIController.DisplayNodeInfo(CurrentNode); } }
/// <summary> /// If the user has started running MCTS, then display information about it to the UI whilst it generates <para/> /// When the MCTS has finished generating, set the position of each <see cref="NodeObject"/> so that they can be rendered on-screen <para/> /// When each nodes position has been set, switch to the tree navigation UI /// </summary> void Update() { //Don't do anything until the user has started running the MCTS if (mcts == null) { return; } //While the MCTS is still running, display progress information about the time remaining and the amounts of nodes created to the user if (!mcts.Finished) { timeLeft -= Time.deltaTime; if (timeLeft <= 0) { mcts.Finish(); } TreeUIController.UpdateProgressBar((1 - (timeLeft / timeToRunFor)) / 2, "Running MCTS " + mcts.UniqueNodes + " nodes " + timeLeft.ToString("0.0") + "s/" + timeToRunFor.ToString("0.0") + "s"); } //Return if the MCTS has not finished being created if (!mcts.Finished) { return; } //If the MCTS has finished being computed, start to create gameobjects for each node in the tree if (!startedVisualisation) { rootNodeObject = (NodeObject)mcts.Root; rootNodeObject.SetPosition(visualisationType); StartCoroutine(SetNodePosition(rootNodeObject)); startedVisualisation = true; } //Display information on the progress bar about how many node objects have been created, until every node in the tree has its own gameobject if (!allNodesGenerated) { if (nodesGenerated < mcts.UniqueNodes) { TreeUIController.UpdateProgressBar(0.5f + ((float)nodesGenerated / mcts.UniqueNodes / 2), "Creating node objects: " + nodesGenerated + "/" + mcts.UniqueNodes); } else if (nodesGenerated == mcts.UniqueNodes) { //If every node has had a gameobject created for it, then switch to the navigation UI and start to render the game tree TreeUIController.SwitchToNavigationUI(); Camera.main.GetComponent <LineDraw>().linesVisible = true; Camera.main.GetComponent <TreeCameraControl>().CurrentNode = rootNodeObject; TreeUIController.DisplayNodeInfo(mcts.Root); allNodesGenerated = true; LineDraw.SelectNode(rootNodeObject); } } }