Esempio n. 1
0
    // Fetch instruction
    protected virtual void DemoUpdate()
    {
        if (newDemoImplemented)
        {
            InstructionBase instruction = null;

            // Step by step activated by pausing, and step requested
            if (userPausedTask && demoManager.PlayerMove)
            {
                demoManager.PlayerMove = false;
                instruction            = demoManager.GetStep();

                bool increment = demoManager.PlayerIncremented;
                PerformInstruction(instruction, increment);
            }
            else if (!userPausedTask && demoManager.HasInstructions()) // Demo mode
            {
                // First check if user test setup is complete
                if (!WaitingForSupportToFinish())//waitForSupportToComplete == 0)
                {
                    instruction = demoManager.GetInstruction();
                    //Debug.Log("Current: " + demoManager.CurrentInstructionNr + ", Actual: " + instruction.InstructionNr);

                    PerformInstruction(instruction, true);
                    demoManager.IncrementToNextInstruction();
                }
            }

            // Debugging
            if (instruction != null && prevInstruction != instruction.Instruction)
            {
                prevInstruction = instruction.DebugInfo();
                Debug.Log(instruction.DebugInfo());

                if (useDebugText && debugText != null)
                {
                    if (deleteWhenReached <= 0)
                    {
                        debugText.text    = instruction.DebugInfo();
                        deleteWhenReached = debugLineNumbers;
                    }
                    else
                    {
                        debugText.text += "\n" + instruction.DebugInfo();
                    }

                    deleteWhenReached--;
                }
            }
        }
    }
Esempio n. 2
0
    public override int PrepareNextInstruction(InstructionBase instruction)
    {
        Debug.Log(instruction.DebugInfo());

        bool gotSortingElement = !insertionSort.SkipDict[UtilSort.SKIP_NO_ELEMENT].Contains(instruction.Instruction);
        bool noDestination     = insertionSort.SkipDict[UtilSort.SKIP_NO_DESTINATION].Contains(instruction.Instruction);

        if (gotSortingElement)
        {
            InsertionSortInstruction insertionSortInstruction = (InsertionSortInstruction)instruction;
            // Get the Sorting element
            InsertionSortElement sortingElement = sortMain.ElementManager.GetSortingElement(insertionSortInstruction.SortingElementID).GetComponent <InsertionSortElement>();

            // Hands out the next instruction
            sortingElement.Instruction = insertionSortInstruction;

            // Give this sorting element permission to give feedback to progress to next intstruction
            switch (instruction.Instruction)
            {
            case UtilSort.PIVOT_START_INST:
            case UtilSort.COMPARE_START_INST:
            case UtilSort.PIVOT_END_INST:
            case UtilSort.SWITCH_INST:
                sortingElement.NextMove = true;
                break;
            }
            //if (instruction.Instruction == UtilSort.PIVOT_START_INST || instruction.Instruction == UtilSort.PIVOT_END_INST || instruction.Instruction == UtilSort.SWITCH_INST)
            //    sortingElement.NextMove = true;
        }

        // Display help on blackboard
        if (sortMain.SortSettings.Difficulty <= UtilSort.BEGINNER)
        {
            sortMain.WaitForSupportToComplete++;
            StartCoroutine(sortMain.GetTeachingAlgorithm().UserTestHighlightPseudoCode(instruction, gotSortingElement));
        }


        if (gotSortingElement && !noDestination)
        {
            return(0);
        }
        return(1);
    }
Esempio n. 3
0
    public override int PrepareNextInstruction(InstructionBase instruction)
    {
        Debug.Log(instruction.DebugInfo());

        bool gotSortingElement = !bubbleSort.SkipDict[UtilSort.SKIP_NO_ELEMENT].Contains(instruction.Instruction);
        bool noDestination     = bubbleSort.SkipDict[UtilSort.SKIP_NO_DESTINATION].Contains(instruction.Instruction);

        if (gotSortingElement)
        {
            // Get the next two instructions
            BubbleSortInstruction bubbleInstruction = (BubbleSortInstruction)instruction;

            // Find the sorting elements for this instruction
            BubbleSortElement s1 = sortMain.ElementManager.GetSortingElement(bubbleInstruction.SortingElementID1).GetComponent <BubbleSortElement>();
            BubbleSortElement s2 = sortMain.ElementManager.GetSortingElement(bubbleInstruction.SortingElementID2).GetComponent <BubbleSortElement>();

            // Hand the instructions out
            s1.Instruction = bubbleInstruction;
            s2.Instruction = bubbleInstruction;

            // Give this sorting element permission to give feedback to progress to next intstruction
            if (instruction.Instruction == UtilSort.COMPARE_START_INST || instruction.Instruction == UtilSort.SWITCH_INST)
            {
                s1.NextMove = true;
                s2.NextMove = true;
            }
        }

        if (sortMain.SortSettings.Difficulty <= Util.BEGINNER)
        {
            sortMain.WaitForSupportToComplete++;
            StartCoroutine(sortMain.GetTeachingAlgorithm().UserTestHighlightPseudoCode(instruction, gotSortingElement));
        }

        if (gotSortingElement && !noDestination)
        {
            return(0);
        }
        return(2);
    }
Esempio n. 4
0
    public override int PrepareNextInstruction(InstructionBase instruction)
    {
        Debug.Log(instruction.DebugInfo());

        bool gotSortingElement = !bucketSort.SkipDict[Util.SKIP_NO_ELEMENT].Contains(instruction.Instruction);
        bool noDestination     = bucketSort.SkipDict[Util.SKIP_NO_DESTINATION].Contains(instruction.Instruction);

        switch (instruction.Instruction)
        {
        case UtilSort.PHASING_INST:
            // Phase into Insertion Sort?
            bucketManager.AutoSortBuckets();
            break;

        case UtilSort.DISPLAY_ELEMENT:
            Debug.Log("Display elements");

            // Display elements on top of bucket
            sortMain.WaitForSupportToComplete++;
            StartCoroutine(bucketManager.PutElementsForDisplay(((BucketSortInstruction)instruction).BucketID));
            return(1);    // Nothing to do for the player, nor any pseudocode
        }

        if (instruction is BucketSortInstruction)
        {
            // Get the next instruction
            BucketSortInstruction bucketSortInstruction = (BucketSortInstruction)instruction;

            // Get the Sorting element
            BucketSortElement sortingElement = sortMain.ElementManager.GetSortingElement(bucketSortInstruction.SortingElementID).GetComponent <BucketSortElement>();

            // Hands out the next instruction
            sortingElement.Instruction = bucketSortInstruction;

            Bucket bucket = bucketManager.GetBucket(bucketSortInstruction.BucketID);
            bucket.BucketSortInstruction = bucketSortInstruction;

            // Give this sorting element permission to give feedback to progress to next intstruction
            if (instruction.Instruction == UtilSort.MOVE_TO_BUCKET_INST || instruction.Instruction == UtilSort.MOVE_BACK_INST)
            {
                sortingElement.NextMove = true;
            }
        }

        // Display help on blackboard
        if (sortMain.SortSettings.Difficulty <= Util.BEGINNER)
        {
            sortMain.WaitForSupportToComplete++;
            StartCoroutine(sortMain.GetTeachingAlgorithm().UserTestHighlightPseudoCode(instruction, gotSortingElement));
        }


        Debug.Log("Element: " + gotSortingElement + ", no destination: " + noDestination);
        if (gotSortingElement && !noDestination)
        {
            return(0);
        }

        Debug.Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>> Nothing for player to do, continuing to next instruction");
        return(1);
    }
Esempio n. 5
0
    // User test
    public int PrepareNextInstruction(InstructionBase instruction)
    {
        string inst = instruction.Instruction;

        Debug.Log(">>> " + instruction.DebugInfo());

        // First check whether the instruction contains a node and/or destination
        bool gotNode       = !graphAlgorithm.SkipDict[Util.SKIP_NO_ELEMENT].Contains(inst);
        bool noDestination = graphAlgorithm.SkipDict[Util.SKIP_NO_DESTINATION].Contains(inst);

        // List visual Update
        if (instruction is ListVisualInstruction)
        {
            // Only provide list visual support until <lvl>
            if (graphSettings.Difficulty > UtilGraph.LIST_VISUAL_MAX_DIFFICULTY)
            {
                return(1);
            }

            ListVisualInstruction listVisualInst = (ListVisualInstruction)instruction;
            listVisual.ExecuteInstruction(listVisualInst, true);

            //Debug.Log("List visual instruction: " + listVisualInst.DebugInfo());
        }
        else
        {
            Node node = null;

            if (gotNode)
            {
                if (instruction is TraverseInstruction)
                {
                    TraverseInstruction traverseInstruction = (TraverseInstruction)instruction;
                    //Debug.Log("Traverse instruction: " + traverseInstruction.DebugInfo());

                    // Get the Sorting element
                    node = traverseInstruction.Node;

                    // Hands out the next instruction
                    node.Instruction = traverseInstruction;

                    // Set goal
                    posManager.CurrentGoal = node;

                    // Reset if pointer must be used on the same node twice
                    if (traverseInstruction.VisitInst && pointer.prevNodeShot == node)
                    {
                        pointer.prevNodeShot = null;
                    }

                    // Reset position manager if the user already stands on top of the node
                    if (traverseInstruction.TraverseInst && posManager.ReportedNode == node)
                    {
                        posManager.ReportedNode = null;
                    }

                    // Give this sorting element permission to give feedback to progress to next intstruction
                    node.NextMove = NextIsUserMove(inst);

                    // Traverse instruction extra
                    switch (inst)
                    {
                    // Highlight the node we are currently going to work at
                    case UtilGraph.DEQUEUE_NODE_INST:
                    case UtilGraph.POP_INST:
                    case UtilGraph.PRIORITY_REMOVE_NODE:
                        // Hide all edge cost to make it easier to see node distances
                        if (graphSettings.GraphTask == UtilGraph.SHORTEST_PATH)
                        {
                            graphManager.MakeEdgeCostVisible(false);
                        }
                        break;

                    case UtilGraph.FOR_ALL_NEIGHBORS_INST:
                        // Make edge cost visible again
                        if (graphSettings.GraphTask == UtilGraph.SHORTEST_PATH)
                        {
                            graphManager.MakeEdgeCostVisible(true);
                        }
                        break;
                    }

                    // Perform list visual instruction in next step (when current instruction has been correctly performed)
                    if (traverseInstruction.ListVisualInstruction != null)
                    {
                        updateListVisualInstruction = traverseInstruction.ListVisualInstruction;
                    }
                }
                else if (instruction is ShortestPathInstruction)
                {
                    ShortestPathInstruction spInst = (ShortestPathInstruction)instruction;
                    //Debug.Log("Shortest path instruction: " + spInst.DebugInfo());

                    // Get the Sorting element
                    if (spInst.CurrentNode != null)
                    {
                        node = spInst.CurrentNode;
                    }
                    else
                    {
                        node = spInst.ConnectedNode;
                    }

                    // Hands out the next instruction
                    node.Instruction = spInst;

                    // Set goal
                    posManager.CurrentGoal = node;

                    // Give this sorting element permission to give feedback to progress to next intstruction
                    node.NextMove = NextIsUserMove(inst);

                    // Shortest path extra
                    switch (inst)
                    {
                    case UtilGraph.IF_DIST_PLUS_EDGE_COST_LESS_THAN:
                        // Turn off highlight effect of previous line
                        pseudoCodeViewer.ChangeColorOfText(8, Util.BLACKBOARD_TEXT_COLOR);

                        // Since we highlighted the color and/or text position of the node/edge we are working on (highlighting purpose) in the previous instruction, now we reset them
                        // Changed color of node
                        spInst.ConnectedNode.CurrentColor = UtilGraph.VISITED_COLOR;
                        // Reset text color/position of the edge cost
                        spInst.CurrentEdge.CurrentColor = UtilGraph.VISITED_COLOR;

                        // Perform sub task: calculate dist (current node) + edge cost to the connected node
                        if (!autoCalculation)
                        {
                            usingCalculator       = true;
                            pointer.AllowShooting = false;
                            calculator.InitCalculation(Calculator.GRAPH_TASK);
                            calculator.SpawnDeviceInfrontOfPlayer();
                        }
                        break;
                    }

                    // Perform list visual instruction in next step (when current instruction has been correctly performed)
                    if (spInst.ListVisualInstruction != null)
                    {
                        updateListVisualInstruction = spInst.ListVisualInstruction;
                    }
                }
            }
        }

        // Display help on blackboard
        if (graphSettings.Difficulty <= Util.PSEUDO_CODE_HIGHTLIGHT_MAX_DIFFICULTY)
        {
            WaitForSupportToComplete++;
            StartCoroutine(graphAlgorithm.UserTestHighlightPseudoCode(instruction, gotNode));// && !noDestination));
        }

        // InstructionBase extra
        switch (inst)
        {
        case UtilGraph.SET_ALL_NODES_TO_INFINITY:
            graphManager.SetAllNodesDist(UtilGraph.INF);
            break;

        case UtilGraph.SET_START_NODE_DIST_TO_ZERO:
            // Find start node and set distance to 0
            Node startNode = graphManager.StartNode;
            startNode.Dist = 0;

            // If list visual: update value
            if (Settings.Difficulty <= UtilGraph.LIST_VISUAL_MAX_DIFFICULTY)
            {
                listVisual.FindNodeRepresentation(startNode).UpdateSurfaceText(UtilGraph.DIST_UPDATE_COLOR);
            }
            break;

        case UtilGraph.MARK_END_NODE:
            Node endNode = graphManager.EndNode;
            endNode.CurrentColor          = UtilGraph.SHORTEST_PATH_COLOR;
            endNode.PrevEdge.CurrentColor = UtilGraph.SHORTEST_PATH_COLOR;
            break;

        case UtilGraph.END_FOR_LOOP_INST:
            if (graphSettings.Difficulty <= UtilGraph.LIST_VISUAL_MAX_DIFFICULTY)
            {
                listVisual.DestroyCurrentNode();
            }
            break;

        case UtilGraph.NO_PATH_FOUND:
        case Util.FINAL_INSTRUCTION:
            // No path found
            WaitForSupportToComplete++;
            StartCoroutine(FinishUserTest());
            break;
        }

        //Debug.Log("Got node: " + gotNode + ", no destination: " + noDestination);
        if (gotNode && !noDestination)
        {
            return(0);
        }
        //Debug.Log("Nothing to do for player, get another instruction");
        return(1);
    }