public IEnumerator parseABCoroutine(MinMaxTree tree) { GetComponent <UIReader>().toggleUI(false, UICode.PARSE_AB, UICode.PARSE_MM, UICode.GENERATE, UICode.MAX_VAL, UICode.MIN_VAL); GetComponent <UIReader>().toggleUI(true, UICode.AB_TEXT); Node root = tree.root; yield return(StartCoroutine(parseABCoroutineHelper(root, Data.minVal - 1, Data.maxVal + 1))); mInfoText.updateText("Tree Parsed! The value of the best move is " + root.val); toggleBestMoveGlow(root); GetComponent <UIReader>().toggleUI(true, UICode.GENERATE, UICode.MAX_VAL, UICode.MIN_VAL); GetComponent <UIReader>().toggleUI(false, UICode.AB_TEXT); }
/// <summary> /// Generates a tree /// </summary> /// <param name="minNodes"> the minimum number of children each node can have </param> /// <param name="maxNodes"> the maximum number of children each node can have </param> /// <param name="depth"> the desired depth of the tree </param> public void generate(int minNodes, int maxNodes, int depth) { mDepthSpacing = 1.5f * Mathf.CeilToInt(maxNodes / 7.0f); clearGameObjects(); mTree = new MinMaxTree(depth); int numNodes = 1; for (int i = 1; i < depth; i++) { List <Node> currentNodes = mTree.getAllNodesAtDepth(i); foreach (Node n in currentNodes) { generateChildren(n, minNodes, maxNodes, i, ref numNodes); } } generateGameObjects(mTree); assignValsToLeafNodes(); }
/// <summary> /// Generates GameObjects for each node in the tree /// </summary> /// <param name="tree"> the tree to generate GameObjects for </param> private void generateGameObjects(MinMaxTree tree) { Vector3 currentPos = Vector3.zero; generateGameObjectsHelper(tree.root, null, currentPos); }
public IEnumerator parseMinMaxCoroutine(MinMaxTree tree) { GetComponent <UIReader>().toggleUI(false, UICode.PARSE_AB, UICode.PARSE_MM, UICode.GENERATE, UICode.MIN_VAL, UICode.MAX_VAL); Node root = tree.root; Node current = root; Node bestMove = null; while (root.isUninitialized()) { // Set the posistion of the camera to the current node mCamera.setPosition(current); mInfoText.updateText("Are there unevaluated children?"); yield return(new WaitForSeconds(WAIT_TIME * Data.timeVal)); if (!current.hasUninitializedChildren()) // If all children of the current node have been evaluated { Comparator compare; int val = evaluateCurrNodeType(current, out compare); yield return(new WaitForSeconds(WAIT_TIME_SHORT * Data.timeVal)); for (int i = 0; i < current.numChildren; i++) { current.children[i].glow(WAIT_TIME * Data.timeVal); if (compare(current.children[i].val, val)) { // If the current child is better than all previous children, discard previous options val = current.children[i].val; current.arrows[current.children[i]].changeColorPerm(ArrowScript.LineColor.GREEN); updateArrowColors(current, i); bestMove = current.children[i]; current.assignNodeVal(val); } else { // Otherwise discard this option current.arrows[current.children[i]].changeColorPerm(ArrowScript.LineColor.RED); if (!current.children[i].isLeaf()) { updateArrowColors(current.children[i], current.children[i].numChildren); } } yield return(new WaitForSeconds(WAIT_TIME * Data.timeVal)); } if (current.parent == null) { break; } // If this is not the root node, return to the parent StartCoroutine(current.parent.arrows[current].changeColor(WAIT_TIME * Data.timeVal, ArrowScript.LineColor.GREEN)); current = current.parent; mInfoText.updateText("Returning to Parent Node"); yield return(new WaitForSeconds(WAIT_TIME * Data.timeVal)); } else { mInfoText.updateText("Yes - Evaluating the next unevaluated child"); yield return(new WaitForSeconds(WAIT_TIME_SHORT)); Node next = current.getNextUninitializedChild(); StartCoroutine(current.arrows[next].changeColor(WAIT_TIME * Data.timeVal, ArrowScript.LineColor.GREEN)); current = next; } } mInfoText.updateText("Tree Parsed! The value of the best node is " + bestMove.val); bestMove.toggleGlow(); root.arrows[bestMove].changeColorPerm(ArrowScript.LineColor.GREEN); GetComponent <UIReader>().toggleUI(true, UICode.GENERATE, UICode.MIN_VAL, UICode.MAX_VAL); }