Example #1
0
        /// <summary>
        /// Called when the start button is pressed <para/>
        /// Initialises the <see cref="mcts"/> tree search object and instantiates the root node <para/>
        /// Also creates as many starting nodes as the user specified
        /// </summary>
        public void StartButtonPressed()
        {
            //Create an empty board instance, which will have whatever game the user chooses assigned to it
            Board board;

            //Assign whatever game board the user has chosen to the board instance
            switch (HashUIController.GetGameChoice)
            {
            case 0:
                board             = new TTTBoard();
                displayBoardModel = false;
                break;

            case 1:
                board             = new C4Board();
                displayBoardModel = true;

                //Create a C4 Board GameObject and obtain a reference to its BoardModelController Component
                GameObject boardModel = Instantiate(Resources.Load("C4 Board", typeof(GameObject))) as GameObject;
                boardModelController = boardModel.GetComponent <BoardModelController>();
                boardModelController.Initialise();
                break;

            case 2:
                board             = new OthelloBoard();
                displayBoardModel = false;
                break;

            default:
                throw new System.Exception("Unknown game type index has been input");
            }

            mcts = new TreeSearch <Node>(board);

            //Calculate the position of the root node and add an object for it to the scene
            Vector3    rootNodePosition = BoardToPosition(mcts.Root.GameBoard);
            GameObject rootNode         = Instantiate(Resources.Load("HashNode"), rootNodePosition, Quaternion.identity) as GameObject;

            rootNode.transform.parent = transform;
            rootNode.GetComponent <HashNode>().AddNode(null, mcts.Root, false);
            rootNode.GetComponent <HashNode>().Initialise(rootNodePosition);

            //Add the root node to the position and object map
            nodePositionMap.Add(rootNodePosition, rootNode);
            nodeObjectMap.Add(mcts.Root, rootNode);

            //Create the amount of starting nodes specified by the user
            for (int i = 0; i < HashUIController.GetStartingNodeInput(); i++)
            {
                PerformStep(true);
            }

            //Swap out the current menu panels
            HashUIController.SetMenuPanelActive(false);
            HashUIController.SetNavigationPanelActive(true);
        }
Example #2
0
        /// <summary>
        /// Called when the start/stop button is pressed <para/>
        /// If MCTS is not running, then it will be started <para/>
        /// If MCTS is running, this will make it finish early
        /// </summary>
        public void StartStopButtonPressed()
        {
            //Starts or ends MCTS depending on when the button is pressed
            if (mcts == null)
            {
                //Create an empty board instance, which will have whatever game the user chooses assigned to it
                Board board;

                //Assign whatever game board the user has chosen to the board instance
                switch (TreeUIController.GetGameChoice)
                {
                case 0:
                    displayBoardModel = false;
                    board             = new TTTBoard();
                    break;

                case 1:
                    displayBoardModel = true;
                    board             = new C4Board();

                    //Create a C4 Board GameObject and obtain a reference to its BoardModelController Component
                    GameObject boardModel = Instantiate(Resources.Load("C4 Board", typeof(GameObject))) as GameObject;
                    boardModelController = boardModel.GetComponent <BoardModelController>();
                    boardModelController.Initialise();
                    break;

                case 2:
                    displayBoardModel = false;
                    board             = new OthelloBoard();
                    break;

                default:
                    throw new System.Exception("Unknown game type index has been input");
                }

                //Assign whatever visualisation type the user has chosen
                switch (TreeUIController.GetVisualisationChoice)
                {
                case 0:
                    visualisationType = VisualisationType.Standard3D;
                    break;

                case 1:
                    visualisationType = VisualisationType.Disk2D;
                    break;

                case 2:
                    visualisationType = VisualisationType.Cone;
                    break;

                default:
                    throw new System.Exception("Unknown visualisation type: encountered");
                }

                //Initialise MCTS on the given game board
                mcts = new TreeSearch <NodeObject>(board);

                //Obtain the time to run mcts for from the input user amount
                timeToRunFor = TreeUIController.GetTimeToRunInput;
                timeLeft     = timeToRunFor;

                //Run mcts asyncronously
                RunMCTS(mcts);
                TreeUIController.StartButtonPressed();
            }
            else
            {
                //Stop the MCTS early
                mcts.Finish();
            }
        }