Esempio n. 1
0
 private void XAMLRadio_Checked(object sender, RoutedEventArgs e)
 {
     RadioButton ck = sender as RadioButton;
     if (ck.IsChecked.Value)
         visType = VisualisationType.XAML;
     else
         visType = VisualisationType.SVG;
 }
Esempio n. 2
0
        /// <summary>
        /// Gives this <see cref=" NodeObject"/> a position in world space depending on its position in the game tree
        /// </summary>
        public void SetPosition(VisualisationType visualisationType)
        {
            NodeObject parentObject = (NodeObject)Parent;

            //Play around with this value to change the structure of the tree depending on depth
            float depthMul = 60;

            if (visualisationType == VisualisationType.Standard3D)
            {
                #region Standard 3D node placement
                //Root node, automatically starts at origin, does not require additional initialisation
                if (Depth == 0)
                {
                    return;
                }

                if (Depth == 1)             //If at depth 1, use the Fibonacci sphere algorithm to evenly distribute all depth 1 nodes in a sphere around the root node
                {
                    #region Fibbonacci Sphere algorithm
                    int   samples   = Parent.Children.Capacity + 1;
                    float offset    = 2f / samples;
                    float increment = Mathf.PI * (3 - Mathf.Sqrt(5));

                    float y   = ((parentObject.ChildPositionsSet * offset) - 1) + (offset / 2);
                    float r   = Mathf.Sqrt(1 - Mathf.Pow(y, 2));
                    float phi = ((parentObject.ChildPositionsSet + 1) % samples) * increment;
                    float x   = Mathf.Cos(phi) * r;
                    float z   = Mathf.Sin(phi) * r;
                    #endregion
                    Position = new Vector3(x, y, z) * depthMul;
                }
                else                        //If at any other depth, position the new node a set distance away from its parent node
                {
                    Position  = parentObject.Position;
                    Position += parentObject.LocalPosition.normalized * depthMul * 2;
                    Vector3 rotationPoint = Position;

                    Vector3 normal = parentObject.LocalPosition;
                    Vector3 tangent;
                    Vector3 t1 = Vector3.Cross(normal, Vector3.forward);
                    Vector3 t2 = Vector3.Cross(normal, Vector3.up);

                    if (t1.magnitude > t2.magnitude)
                    {
                        tangent = t1;
                    }
                    else
                    {
                        tangent = t2;
                    }

                    if (Parent.Children.Count != 1)
                    {
                        Position += tangent.normalized * depthMul * 0.25f;
                        Position  = Position.RotateAround(rotationPoint, rotationPoint - parentObject.Position, (360 / Parent.Children.Capacity) * parentObject.ChildPositionsSet);
                    }
                }
                #endregion
            }
            else if (visualisationType == VisualisationType.Disk2D)
            {
                #region Disk 2D node placement
                //Root node, automatically starts at origin, does not require additional initialisation
                if (Depth == 0)
                {
                    ArcAngle = 360;
                    return;
                }

                if (Depth == 1)             //If at depth 1, place the new node on the edge of a circle around the origin
                {
                    Position = new Vector3(60, 0, 0);
                    Position = Position.RotateAround(Vector3.zero, Vector3.up, parentObject.ChildPositionsSet * (parentObject.ArcAngle / parentObject.Children.Count));
                }
                else                        //If at any other depth, position the new node a set distance away from its parent node
                {
                    Position  = parentObject.Position;
                    Position += (parentObject.LocalPosition.normalized * depthMul);
                    Position  = Position.RotateAround(parentObject.Position, Vector3.up, -(parentObject.ArcAngle / 2) + (parentObject.ChildPositionsSet * (parentObject.ArcAngle / parentObject.Children.Count)));
                }
                ArcAngle = parentObject.ArcAngle / parentObject.Children.Count;
                #endregion
            }
            else if (visualisationType == VisualisationType.Cone)
            {
                #region Cone node placement
                //Root node, automatically starts at origin, does not require additional initialisation
                if (Depth == 0)
                {
                    Radius = 1000;
                    return;
                }

                Position = parentObject.Position;

                if (parentObject.Children.Count > 1)
                {
                    Position += new Vector3(parentObject.Radius, 0, 0);
                    Position  = Position.RotateAround(parentObject.Position, Vector3.up, parentObject.ChildPositionsSet * (360 / parentObject.Children.Count));

                    Vector3 a = parentObject.Position + new Vector3(parentObject.Radius, 0, 0);
                    Vector3 b = a.RotateAround(parentObject.Position, Vector3.up, 360 / parentObject.Children.Count);
                    Radius = (a - b).magnitude / 2;
                }
                else
                {
                    Radius = parentObject.Radius;
                }

                Position += new Vector3(0, -150, 0);
                #endregion
            }
            else
            {
                throw new System.Exception("Unknown visualisation type: " + visualisationType.ToString() + " encountered");
            }

            parentObject.ChildPositionsSet++;
        }
Esempio n. 3
0
    void handleQuestion(Question question)
    {
        if (question == null)
        {
            return;
        }

        if (needToReloadBars)
        {
            destroyInPlaceBars();
            addInPlaceBars();
            needToReloadBars = false;
        }

        DataPointsManager.Instance.resetPosing();

        bool changed = (_visualisationType != question.visualisationType);

        if (changed)
        {
            _visualisationType = question.visualisationType;

            var barCone = _player.GetComponentInChildren <ConeRenderer>();
            var mapCone = _player.GetComponentInChildren <ConeMapRenderer>();

            switch (_visualisationType)
            {
            case VisualisationType.InPlaceBars:
                //destroyInPlaceBars();
                //addInPlaceBars();
                barCone.clearData();
                mapCone.clearData();
                _leftController._attachedCone  = null;
                _rightController._attachedCone = null;
                break;

            case VisualisationType.BarCone:
                //destroyInPlaceBars();
                //addBlankBars();
                _leftController._attachedCone  = barCone;
                _rightController._attachedCone = barCone;
                barCone.initializeWithData();
                mapCone.clearData();
                break;

            case VisualisationType.MapCone:
                //destroyInPlaceBars();
                barCone.clearData();
                //addBlankBars();
                _leftController._attachedCone  = mapCone;
                _rightController._attachedCone = mapCone;
                mapCone.initializeWithData();
                break;
            }
        }

        _leftController.questionTask  = question.task;
        _rightController.questionTask = question.task;

        switch (question.task)
        {
        case Task.EstimateSinglePoint:
            handleEstimateQuestion(question);
            break;

        case Task.PickLargerDataPoint:
            handleOptionQuestion(question);
            break;

        case Task.PickCloserDataPoint:
            handleOptionQuestion(question);
            break;

        default:
            break;
        }
    }
Esempio n. 4
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();
            }
        }