Esempio n. 1
0
    public override void InstantiateSafeStart()
    {
        // First init common stuff
        base.InstantiateSafeStart();

        // >>> Grab variable data from settings
        string teachingMode   = graphSettings.TeachingMode;
        int    difficulty     = graphSettings.Difficulty;
        float  algorithmSpeed = graphSettings.AlgorithmSpeed;


        string graphTask      = graphSettings.GraphTask; //..
        string graphStructure = graphSettings.GraphStructure;
        string edgeType       = graphSettings.EdgeType;
        string edgeBuildMode  = graphSettings.EdgeBuildMode;

        int[] graphSetup = graphSettings.GraphSetup();

        // Extra
        bool shortestPathOneToAll = graphSettings.ShortestPathOneToAll;

        // Only works for Demo as for now,
        if (shortestPathOneToAll && graphSettings.IsUserTest())
        {
            shortestPathOneToAll = false;
        }

        // >>> Init Algorithm
        graphAlgorithm = (GraphAlgorithm)GrabAlgorithmFromObj();
        graphAlgorithm.InitGraphAlgorithm(this, graphStructure, algorithmSpeed, shortestPathOneToAll);

        // >>> Init Graph manager
        bool isShortestPath = graphTask == UtilGraph.SHORTEST_PATH;
        int  minEdge        = graphSettings.MinEdgeCost;
        int  maxEdge        = graphSettings.MaxEdgeCost;

        graphManager = ActivateDeactivateGraphComponents(graphSettings.GraphStructure);
        graphManager.InitGraphManager(algorithmName, graphStructure, edgeType, isShortestPath, graphSettings.RNGDict(), listVisual, minEdge, maxEdge);

        // Graph setup (rows/colums - tree depth/nTree - random?)
        graphManager.InitGraph(graphSetup);

        // Create graph based on init variables
        graphManager.CreateGraph(edgeBuildMode);

        // >>> Init position manager
        posManager.InitPositionManager(isShortestPath);

        // >>> Support
        blackboard.ChangeText(0, algorithmName);

        bool includeLineNr = Settings.PseudocodeLineNr;
        bool inDetailStep  = Settings.PseudocodeStep;

        // Prepare difficulty level related stuff for user test (copied from sort)
        pseudoCodeViewer.InitPseudoCodeViewer(graphAlgorithm, includeLineNr, inDetailStep);
        if (graphSettings.TeachingMode == Util.USER_TEST)
        {
            if (difficulty <= Util.PSEUDO_CODE_MAX_DIFFICULTY)
            {
                // Pseudocode
                pseudoCodeViewer.PseudoCodeSetup();
                // Fix pseudocode for graph
                pseudoCodeViewer.ChangeSizeOfPseudocode(pseudocodeChangeSizeStartPos);
            }

            if (difficulty <= UtilGraph.LIST_VISUAL_MAX_DIFFICULTY)
            {
                // List visual
                string listType = graphAlgorithm.GetListType();
                listVisual.InitListVisual(listType, algorithmSpeed);
                //AddToCheckList(UtilGraph.LIST_VISUAL);
            }
        }
        else
        {
            // >>> Demo
            // Pseudocode
            pseudoCodeViewer.PseudoCodeSetup();

            // Fix pseudocode for graph
            pseudoCodeViewer.ChangeSizeOfPseudocode(pseudocodeChangeSizeStartPos);

            // List visual
            listVisual.InitListVisual(graphAlgorithm.GetListType(), algorithmSpeed);
        }

        // Hide menu
        StartCoroutine(ActivateTaskObjects(true));

        // Init start pillar
        bool selectNodes = graphSettings.SelectStartEndNodes;

        startPillar.InitStartPillar(teachingMode, selectNodes, isShortestPath);

        // If user want to select nodes, then start button will become inactive until node(s) have been chosen
        if (selectNodes)
        {
            // Start node
            chosenNodes           = 0;
            numberOfNodesToChoose = 1;

            // End node
            if (isShortestPath)
            {
                numberOfNodesToChoose++;
            }

            // Init pointer with start task
            pointer.InitPointer(UtilGraph.SELECT_NODE, numberOfNodesToChoose);

            // Start check list
            activeChecklist     = START_UP_CHECK;
            checkListModeActive = true;
        }
        else
        {
            StartCoroutine(SetAutomaticallyImportantNodes(isShortestPath));
        }
    }