void UpdateValues() { Util.Draw._shapeColor = defaultColor; Util.Settings._shapeDrawType = drawType; if (Util.Settings.enabled) { Util.OnGUI = textDebugging; Util._UtilOnGUI.GetComponent <UtilOnGUI>().textSize = debugLineTextSize; Util._UtilOnGUI.GetComponent <UtilOnGUI>().textColor = debugLineColor; Util._UtilOnGUI.GetComponent <UtilOnGUI>().textBackground = debugLineBackground; Util._UtilOnGUI.GetComponent <UtilOnGUI>().debugWindowWidth = debugWindowWidth; Util._UtilOnGUI.GetComponent <UtilOnGUI>().debugWindowHeight = debugWindowHeight; Util.OnGUIObject = objectDebugging; Util._UtilOnGUI.GetComponent <UtilOnGUI>().objectTextSize = debugObjectTextSize; Util._UtilOnGUI.GetComponent <UtilOnGUI>().objectTextColor = debugObjectColor; Util._UtilOnGUI.GetComponent <UtilOnGUI>().objectTextBackground = debugObjectBackground; Util._UtilOnGUI.GetComponent <UtilOnGUI>().scaleWithDistace = scaleWithDistance; UtilGraph.DrawGraphs = drawGraph; UtilGraph.ChangeOutlineSize(graphRect); UtilGraph.updateTime = graphUpdateTime; } }
private void Awake() { // Set ID's nodeID = NODE_ID++; NodeAlphaID = UtilGraph.ConvertIDToAlphabet(nodeID); // Name shown in the editor name = NodeType + nodeID + "(" + nodeAlphaID + ")"; animator = GetComponentInChildren <Animator>(); // Get textmesh pros Component[] textHolders = GetComponentsInChildren(typeof(TextMeshPro)); textNodeID = textHolders[0].GetComponent <TextMeshPro>(); textNodeDist = textHolders[1].GetComponent <TextMeshPro>(); // Find player object and its camera positionManager = FindObjectOfType <PositionManager>(); graphMain = FindObjectOfType <GraphMain>(); audioManager = FindObjectOfType <AudioManager>(); // "Set" edges = new List <Edge>(); ResetNode(); }
public void ReportPlayerOnNode(Node node) { // Set previous node if (node != reportedNode) { previousNode = reportedNode; } // Set reported node reportedNode = node; // Fix pseudocode size pseudoCodeViewer.ChangeSizeOfPseudocode(node.transform.position); // Rotate all node text toward player RotateNodesTowards(node.transform.position); // Display information about the node the player currently is standing on SetPlayerPositionText(node.NodeAlphaID.ToString()); if (showDistance) { nodeDistText.text = "Node dist: " + UtilGraph.ConvertDist(node.Dist); } otherAreaPositionUpdated = false; }
protected void CreateEdge(Node node1, Node node2, Vector3 centerPos, float angle) { // Instantiate and fix edge GameObject edge = null; float length = UtilGraph.DistanceBetweenNodes(node1.transform, node2.transform); // Set cost if algorithm requires it int edgeCost = UtilGraph.NO_COST; if (isShortestPath) { edgeCost = Random.Range(minEdgeCost, maxEdgeCost + 1); // include 100 } // Initialize edge switch (edgeType) { case UtilGraph.UNDIRECTED_EDGE: edge = Instantiate(undirectedEdgePrefab, centerPos, Quaternion.identity); edge.AddComponent <UnDirectedEdge>(); edge.GetComponent <UnDirectedEdge>().InitUndirectedEdge(node1, node2, edgeCost, UtilGraph.GRID_GRAPH); break; case UtilGraph.DIRECED_EDGE: bool pathBothWaysActive = RollSymmetricEdge(); if (pathBothWaysActive) { edge = Instantiate(symmetricDirectedEdgePrefab, centerPos, Quaternion.identity); } else { edge = Instantiate(directedEdgePrefab, centerPos, Quaternion.identity); } edge.AddComponent <DirectedEdge>(); edge.GetComponent <DirectedEdge>().InitDirectedEdge(node1, node2, edgeCost, UtilGraph.GRID_GRAPH, pathBothWaysActive); break; } edge.GetComponent <Edge>().SetAngle(angle); edge.GetComponent <Edge>().SetLength(length); edge.transform.parent = edgeContainerObject.transform; edges.Add(edge); // Just for testing if (testIsland) { int[] cell = ((GridNode)node1).Cell; int nodeID = node1.NodeID; if (cell[0] >= 5 && cell[0] <= 25 && cell[1] >= 5 && cell[1] <= 25) //if (nodeID > 500 && nodeID < 550) { edge.GetComponent <Edge>().Cost = 100000; //edge.GetComponent<Edge>().CurrentColor = Color.white; } } }
protected IEnumerator HighlightPseudoCode(string text, Color color) { // Invalid pseudocode linenr check if (text != Util.INVALID_PSEUDO_CODE_LINE) { string[] lineOfCodeSplit = text.Split(Util.PSEUDO_SPLIT_LINE_ID); // Check if LineNr + pseudocode line is present if (lineOfCodeSplit.Length == 2) { int index = UtilGraph.ConvertCostToInt(lineOfCodeSplit[0]); string pseudoCodeLine = lineOfCodeSplit[1]; /* If a calculation takes place, then first display formula/pseudocode -> insert values -> result * E.g.: * Step 1: i = i + 1 * Step 2: i = 1 + 1 * Step 3: i = 2 */ if (pseudoCodeViewer.InDetailStep) { bool valuesNotInserted = true; // First show step 1 for (int x = 0; x < 2; x++) { string pseudoCodeLineStep = PseudocodeLineIntoSteps(index, valuesNotInserted); if (pseudoCodeLineStep == Util.INVALID_PSEUDO_CODE_LINE) { break; } pseudoCodeViewer.SetCodeLine(index, pseudoCodeLineStep, color); yield return(stepDuration); valuesNotInserted = false; // Then show step 2 } } // At last show step 3 (result) pseudoCodeViewer.SetCodeLine(index, pseudoCodeLine, color); } else { Debug.LogError("Incorrect splitlength! Split char found within pseudocode line!!!"); } } if (pseudoCodeViewer.InDetailStep) { yield return(stepDuration); } else { yield return(demoStepDuration); } }
private void SetNodeTextID(bool useAlpha) { if (useAlpha) { textNodeID.text = UtilGraph.ConvertIDToAlphabet(nodeID).ToString(); } else { textNodeID.text = nodeID.ToString(); } }
void Awake() { m = new Material("Shader \"Lines/Colored Blended\" {" + "SubShader {Tags { \"RenderType\"=\"Overdraw\" } Pass { " + "ZWrite Off ZTest Always Cull Off Fog { Mode Off } " + "BindChannels {" + "Bind \"vertex\", vertex Bind \"color\", color }" + "} } }"); _graph = this; _plotPoints = new Dictionary <string, List <Tuple <float, float> > >(); updateTimer = updateTime; }
private IEnumerator UpdateTextNodeDist(int newDist) { textNodeDist.text = UtilGraph.ConvertDist(newDist); for (int i = 0; i < 4; i++) { textNodeDist.color = currentColor; yield return(selectedDuration); textNodeDist.color = UtilGraph.STANDARD_COST_TEXT_COLOR; yield return(selectedDuration); } }
public void SetSurfaceText(char id, int value) { for (int i = 0; i < surfaceTexts.Length; i++) { if (i % 2 == 0) { surfaceTexts[i].text = id.ToString(); } else { surfaceTexts[i].text = UtilGraph.ConvertDist(value); } } }
public void SetCodeLine(string text, Color color) { string[] lineOfCodeSplit = text.Split(Util.PSEUDO_SPLIT_LINE_ID); int index = UtilGraph.ConvertCostToInt(lineOfCodeSplit[0]); if (ValidIndex(index)) { if (includeLineNr) { codeLines[index].text = AdjustLineNr(index, lineOfCodeSplit[1]); } else { codeLines[index].text = lineOfCodeSplit[1]; } codeLines[index].color = color; } }
public string IfStatementContent() { return(UtilGraph.ConvertDist(value1) + " + " + UtilGraph.ConvertDist(value2) + " < " + UtilGraph.ConvertDist(value3)); }
protected override string PseudocodeLineIntoSteps(int lineNr, bool init) { switch (lineNr) { //case 6: return init ? " w <- list.PriorityRemove()" : " " + node1Alpha + " <- list.PriorityRemove()"; //case 7: return init ? " for all neighbors of w in Graph:" : " for all neighbors of " + node1Alpha + " in Graph:"; //case 8: return init ? " Relax neighbor v" : " Relax neighbor " + node2Alpha; case 9: return(init ? " if (" + node1Alpha + ".Dist + edge(" + node1Alpha + ", " + node2Alpha + ").Cost < " + node2Alpha + ".Dist):" : " if (" + node1Dist + " + " + edgeCost + " < " + UtilGraph.ConvertDist(node2Dist) + "):"); default: return(Util.INVALID_PSEUDO_CODE_LINE); } }
private string CreateIfStatementContent(int currentNodeDist, int edgeCost, int connectedNodeDist) { // Change color of if statement useHighlightColor = UseConditionColor(currentNodeDist + edgeCost < connectedNodeDist); return(currentNodeDist + " + " + edgeCost + " < " + UtilGraph.ConvertDist(connectedNode.Dist)); }
// Dijkstra on Tree: must start at 0, or atleast have end node in the same subtree underneath start node #region Dijkstra Demo (OLD: Not used anymore) public IEnumerator ShortestPathDemo(Node startNode, Node endNode) { // Line 0: Set graph/start node SetNodePseudoCode(startNode, 1); // Pseudocode yield return(HighlightPseudoCode(CollectLine(0), Util.BLACKBOARD_TEXT_COLOR)); // Line 1: Set all vertices of G to inifity graphMain.GraphManager.SetAllNodesDist(UtilGraph.INF); yield return(HighlightPseudoCode(CollectLine(1), Util.HIGHLIGHT_STANDARD_COLOR)); // Line 2: Create (priority) list List <Node> list = new List <Node>(); yield return(HighlightPseudoCode(CollectLine(2), Util.HIGHLIGHT_STANDARD_COLOR)); // Line 3: Add starting node and set its cost to 0 list.Add(startNode); startNode.Visited = true; SetNodePseudoCode(startNode, 1, 0); // PseudoCode (line 3+4) graphMain.UpdateListVisual(UtilGraph.PRIORITY_ADD_NODE, startNode, 0); //listVisual.PriorityAdd(startNode, 0); // List visual yield return(HighlightPseudoCode(CollectLine(3), Util.HIGHLIGHT_STANDARD_COLOR)); // Line 4: Set total cost (Dist) of start node to 0 yield return(HighlightPseudoCode(CollectLine(4), Util.HIGHLIGHT_STANDARD_COLOR)); lengthOfList = "1"; while (list.Count > 0 && !objectiveFound) { #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion // Line 5: Update while-loop yield return(HighlightPseudoCode(CollectLine(5), Util.HIGHLIGHT_STANDARD_COLOR)); #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion // Node currentNode = list[list.Count - 1]; list.RemoveAt(list.Count - 1); currentNode.DisplayEdgeCost(true); SetNodePseudoCode(currentNode, 1); // PseudoCode graphMain.UpdateListVisual(UtilGraph.REMOVE_CURRENT_NODE, null, Util.NO_VALUE); // listVisual.RemoveCurrentNode(); // List visual currentNode.CurrentColor = UtilGraph.TRAVERSE_COLOR; // Line 6: Remove element with lowest distance yield return(HighlightPseudoCode(CollectLine(6), Util.HIGHLIGHT_STANDARD_COLOR)); #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion // Stop search if end node found and we dont want shortest path to all - stop when first visited instead? (not always global optimal) if (!shortestPathOnToAll && currentNode == endNode) { objectiveFound = true; continue; } // Check all nodes connected with current node List <Edge> edges = currentNode.Edges; numberOfEdges = edges.Count; // Pseudocode // Line 7: Update for-loop (if no nodes connected) if (numberOfEdges == 0) { i = 0; // not used anymore yield return(HighlightPseudoCode(CollectLine(7), Util.HIGHLIGHT_STANDARD_COLOR)); } #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion for (int i = 0; i < numberOfEdges; i++) { #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion // Line 7: Update for-loop this.i = i; yield return(HighlightPseudoCode(CollectLine(7), Util.HIGHLIGHT_STANDARD_COLOR)); #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion // Checking edge Edge currentEdge = edges[i]; // Dont check edge we came from if (currentEdge == currentNode.PrevEdge) { continue; } // Checking node on the other side of the edge Node connectedNode = currentEdge.OtherNodeConnected(currentNode); if (connectedNode == null || connectedNode.Traversed) { continue; //currentEdge.CurrentColor = Util.STANDARD_COLOR; } SetEdge(currentEdge); // Pseudocode yield return(demoStepDuration); #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion SetNodePseudoCode(connectedNode, 2); // PseudoCode if (!connectedNode.Visited) { connectedNode.Visited = true; } // Line 8: visit connected node yield return(HighlightPseudoCode(CollectLine(8), Util.HIGHLIGHT_STANDARD_COLOR)); #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion // Cost between nodes int currentDistAndEdgeCost = node1Dist + edgeCost; ifStatementContent = currentDistAndEdgeCost + " < " + UtilGraph.ConvertDist(node2Dist); // Line 9: If statement yield return(HighlightPseudoCode(CollectLine(9), Util.HIGHLIGHT_STANDARD_COLOR)); #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion // Update cost of connected node if (currentDistAndEdgeCost < connectedNode.Dist) { // Line 10: Update total cost (Dist) of connected node (w) connectedNode.Dist = currentDistAndEdgeCost; yield return(HighlightPseudoCode(CollectLine(10), Util.HIGHLIGHT_STANDARD_COLOR)); #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion // Line 11: Update prev edge (Prev) of connected node (w) connectedNode.PrevEdge = currentEdge; yield return(HighlightPseudoCode(CollectLine(11), Util.HIGHLIGHT_STANDARD_COLOR)); #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion if (!list.Contains(connectedNode)) { list.Add(connectedNode); } // Sort list such that the lowest distance node gets out first list.Sort(); // List visual if (graphMain.Settings.Difficulty < Util.ADVANCED) { int index = list.IndexOf(connectedNode); //(list.Count - 1 ) - list.IndexOf(connectedNode); // OBS: list is inverted (removes the last element instead of index 0) //int currentNodeRepIndex = graphMain.ListVisual.ListIndexOf(connectedNode); // Create method/action code ??? if (!graphMain.CheckListVisual(UtilGraph.HAS_NODE_REPRESENTATION, connectedNode)) // listVisual.HasNodeRepresentation(connectedNode)) { graphMain.UpdateListVisual(UtilGraph.PRIORITY_ADD_NODE, connectedNode, index); // listVisual.PriorityAdd(connectedNode, index); // Node representation } else { yield return(graphMain.ListVisual.UpdateValueAndPositionOf(connectedNode, index, true)); // Create method/action code ??? } } #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion // Line 12: Add to list yield return(HighlightPseudoCode(CollectLine(12), Util.HIGHLIGHT_STANDARD_COLOR)); } #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion currentEdge.CurrentColor = UtilGraph.VISITED_COLOR; // Line 13: End if yield return(HighlightPseudoCode(CollectLine(13), Util.HIGHLIGHT_STANDARD_COLOR)); } #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion // Line 14: End for-loop yield return(HighlightPseudoCode(CollectLine(14), Util.HIGHLIGHT_STANDARD_COLOR)); #region Stop demo // Check if user wants to stop the demo if (graphMain.UserStoppedTask) { break; } #endregion currentNode.Traversed = true; lengthOfList = list.Count.ToString(); // PseudoCode graphMain.UpdateListVisual(UtilGraph.DESTROY_CURRENT_NODE, null, Util.NO_VALUE); // listVisual.DestroyCurrentNode(); // Node Representation } // Line 15: End while-loop yield return(HighlightPseudoCode(CollectLine(15), Util.HIGHLIGHT_STANDARD_COLOR)); if (graphMain.UserStoppedTask) { graphMain.UpdateCheckList(Util.DEMO, true); } else { isTaskCompleted = true; } }
// Used by position manager to turn on text again public void DisplayNodeInfo() { SetNodeTextID(true); textNodeDist.text = UtilGraph.ConvertDist(dist); }