public override IEnumerator UserTestHighlightPseudoCode(InstructionBase instruction, bool gotSortingElement) { // Gather information from instruction BucketSortInstruction bucketInstruction = null; BucketSortElement sortingElement = null; if (gotSortingElement) { bucketInstruction = (BucketSortInstruction)instruction; // Change internal state of sorting element sortingElement = sortMain.ElementManager.GetSortingElement(bucketInstruction.SortingElementID).GetComponent <BucketSortElement>(); } if (instruction is InstructionLoop) { InstructionLoop loopInst = (InstructionLoop)instruction; i = loopInst.I; j = loopInst.J; k = loopInst.K; loopType = loopInst.LoopType; } // Remove highlight from previous instruction pseudoCodeViewer.ChangeColorOfText(prevHighlightedLineOfCode, Util.BLACKBOARD_TEXT_COLOR); // Gather part of code to highlight int lineOfCode = Util.NO_VALUE; useHighlightColor = Util.HIGHLIGHT_STANDARD_COLOR; switch (instruction.Instruction) { case Util.FIRST_INSTRUCTION: lineOfCode = FirstInstructionCodeLine(); SetLengthOfList(); numberOfBuckets = bucketSortManager.NumberOfBuckets.ToString(); break; case UtilSort.CREATE_BUCKETS_INST: lineOfCode = 1; break; case UtilSort.FIRST_LOOP: lineOfCode = 2; useHighlightColor = UseConditionColor(i != lengthOfListInteger); break; case UtilSort.BUCKET_INDEX_INST: lineOfCode = 3; PreparePseudocodeValue(sortingElement.Value, 1); bucketIndex = bucketInstruction.BucketID; bucketIndexStr = bucketIndex.ToString(); //sortingElement.IsCompare = bucketInstruction.IsCompare; UtilSort.IndicateElement(sortingElement.gameObject); break; case UtilSort.MOVE_TO_BUCKET_INST: lineOfCode = 4; useHighlightColor = Util.HIGHLIGHT_USER_ACTION; PreparePseudocodeValue(sortingElement.Value, 1); UtilSort.IndicateElement(sortingElement.gameObject); //sortingElement.IsCompare = bucketInstruction.IsCompare; break; case UtilSort.END_LOOP_INST: switch (loopType) { case UtilSort.OUTER_LOOP: lineOfCode = 5; break; case UtilSort.INNER_LOOP: lineOfCode = 12; break; default: Debug.LogError(UtilSort.END_LOOP_INST + ": '" + loopType + "' loop not found"); break; } break; case UtilSort.PHASING_INST: lineOfCode = 6; break; case Util.SET_VAR_K: lineOfCode = 7; break; case UtilSort.UPDATE_LOOP_INST: if (loopType == UtilSort.OUTER_LOOP) // 2nd loop (outher) { //j = 0; lineOfCode = 8; useHighlightColor = UseConditionColor(i != j); } else // 2nd loop (inner) { lineOfCode = 9; bucketSize = k.ToString(); useHighlightColor = UseConditionColor(j != k); } break; case UtilSort.MOVE_BACK_INST: lineOfCode = 10; useHighlightColor = Util.HIGHLIGHT_USER_ACTION; PreparePseudocodeValue(sortingElement.Value, 2); break; case Util.UPDATE_VAR_K: lineOfCode = 11; kPlus1 = (k + 1).ToString(); break; case Util.FINAL_INSTRUCTION: lineOfCode = FinalInstructionCodeLine(); break; } // Highlight part of code in pseudocode yield return(HighlightPseudoCode(CollectLine(lineOfCode), useHighlightColor)); // Mark prev for next round prevHighlightedLineOfCode = lineOfCode; sortMain.WaitForSupportToComplete--; }
public override IEnumerator ExecuteDemoInstruction(InstructionBase instruction, bool increment) { // Gather information from instruction BucketSortInstruction bucketInstruction = null; BucketSortElement sortingElement = null; if (instruction is BucketSortInstruction) { bucketInstruction = (BucketSortInstruction)instruction; // Change internal state of sorting element sortingElement = sortMain.ElementManager.GetSortingElement(bucketInstruction.SortingElementID).GetComponent <BucketSortElement>(); bucketIndex = bucketInstruction.BucketID; } if (instruction is InstructionLoop) { InstructionLoop loopInst = (InstructionLoop)instruction; i = loopInst.I; j = loopInst.J; k = loopInst.K; loopType = loopInst.LoopType; } // Remove highlight from previous instruction pseudoCodeViewer.ChangeColorOfText(prevHighlightedLineOfCode, Util.BLACKBOARD_TEXT_COLOR); // Gather part of code to highlight int lineOfCode = Util.NO_VALUE; useHighlightColor = Util.HIGHLIGHT_STANDARD_COLOR; switch (instruction.Instruction) { case Util.FIRST_INSTRUCTION: lineOfCode = FirstInstructionCodeLine(); SetBuckets(increment); break; case UtilSort.CREATE_BUCKETS_INST: lineOfCode = 1; SetBuckets(increment); break; case UtilSort.FIRST_LOOP: lineOfCode = 2; if (increment) { SetLengthOfList(); useHighlightColor = UseConditionColor(i != lengthOfListInteger); } else { if (i == 0) { lengthOfList = "len(list)"; } else { i -= 1; } } break; case UtilSort.BUCKET_INDEX_INST: lineOfCode = 3; PreparePseudocodeValue(sortingElement.Value, 1); bucketIndex = bucketInstruction.BucketID; if (increment) { sortingElement.IsCompare = bucketInstruction.IsCompare; bucketIndexStr = bucketIndex.ToString(); } else { sortingElement.IsCompare = !bucketInstruction.IsCompare; bucketIndexStr = "list[i] * N / MAX_VALUE"; } UtilSort.IndicateElement(sortingElement.gameObject); break; case UtilSort.MOVE_TO_BUCKET_INST: lineOfCode = 4; if (increment) { PreparePseudocodeValue(sortingElement.Value, 1); bucketIndex = bucketInstruction.BucketID; sortingElement.IsCompare = bucketInstruction.IsCompare; } else { element1Value = "list[i]"; //bucketIndex = ""; // TODO ? sortingElement.IsCompare = !bucketInstruction.IsCompare; } UtilSort.IndicateElement(sortingElement.gameObject); break; case UtilSort.END_LOOP_INST: switch (loopType) { case UtilSort.OUTER_LOOP: lineOfCode = 5; break; case UtilSort.INNER_LOOP: lineOfCode = 12; break; default: Debug.LogError(UtilSort.END_LOOP_INST + ": '" + loopType + "' loop not found"); break; } break; case UtilSort.PHASING_INST: lineOfCode = 6; i = 0; // ???? j = (bucketSortManager.NumberOfBuckets - 1); bucketIndex = j; // Sort buckets bucketManager.AutoSortBuckets(); break; case UtilSort.DISPLAY_ELEMENT: // TODO: Fix //sortMain.WaitForSupportToComplete++; // add to list? StartCoroutine(bucketManager.PutElementsForDisplay(bucketInstruction.BucketID)); if (!increment) { bucketManager.GetBucket(bucketIndex).SetEnterTrigger(true); } break; case Util.SET_VAR_K: lineOfCode = 7; break; case UtilSort.UPDATE_LOOP_INST: if (loopType == UtilSort.OUTER_LOOP) // 2nd loop (outher) { //j = 0; lineOfCode = 8; if (increment) { numberOfBuckets = bucketSortManager.NumberOfBuckets.ToString(); useHighlightColor = UseConditionColor(i != j); } else { if (i > 0) { i -= 1; } else { numberOfBuckets = "N"; } } } else // 2nd loop (inner) { lineOfCode = 9; if (increment) { bucketSize = k.ToString(); useHighlightColor = UseConditionColor(j != k); } else { if (j > 0) { j--; } else { bucketSize = k.ToString(); } } } break; case UtilSort.MOVE_BACK_INST: lineOfCode = 10; k = bucketInstruction.NextHolderID; // ??? if (increment) { PreparePseudocodeValue(sortingElement.Value, 2); sortingElement.IsSorted = bucketInstruction.IsSorted; } else { element2Value = "buckets[" + i + "][" + j + "]"; sortingElement.IsSorted = !bucketInstruction.IsSorted; } break; case Util.UPDATE_VAR_K: lineOfCode = 11; if (increment) { kPlus1 = (k + 1).ToString(); } else { //if (k > 0) // kPlus1 = (k - 1).ToString(); //else kPlus1 = "k + 1"; } break; case Util.FINAL_INSTRUCTION: lineOfCode = FinalInstructionCodeLine(); IsTaskCompleted = increment; break; } // Highlight part of code in pseudocode if (instruction.Instruction == UtilSort.DISPLAY_ELEMENT) { yield return(null); } else { yield return(HighlightPseudoCode(CollectLine(lineOfCode), useHighlightColor)); prevHighlightedLineOfCode = lineOfCode; } // Move sorting element if (instruction is BucketSortInstruction) { switch (bucketInstruction.Instruction) { case UtilSort.MOVE_TO_BUCKET_INST: if (increment) { sortingElement.transform.position = bucketManager.GetBucket(bucketInstruction.BucketID).transform.position + UtilSort.ABOVE_BUCKET_VR; } else { sortingElement.transform.position = bucketSortManager.GetCorrectHolder(bucketInstruction.HolderID).transform.position + UtilSort.ABOVE_HOLDER_VR; sortingElement.gameObject.SetActive(true); bucketManager.GetBucket(bucketIndex).RemoveSortingElement(sortingElement); sortingElement.RigidBody.constraints = RigidbodyConstraints.None; } break; case UtilSort.DISPLAY_ELEMENT: if (increment) { sortingElement.transform.position = bucketManager.GetBucket(bucketInstruction.BucketID).transform.position + UtilSort.ABOVE_BUCKET_VR; sortingElement.gameObject.SetActive(true); } else { sortingElement.gameObject.SetActive(false); } break; case UtilSort.MOVE_BACK_INST: if (increment) { sortingElement.transform.position = bucketSortManager.GetCorrectHolder(bucketInstruction.NextHolderID).transform.position + UtilSort.ABOVE_HOLDER_VR; } else { sortingElement.transform.position = bucketManager.GetBucket(bucketInstruction.BucketID).transform.position + UtilSort.ABOVE_BUCKET_VR; } break; } } // Display element reports itself when it's done if (instruction.Instruction != UtilSort.DISPLAY_ELEMENT) { sortMain.WaitForSupportToComplete--; } }