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; }
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 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); }