private void PrintPath(Node dest) { if (dest.Previous != null) { PrintPath(dest.Previous); Console.Write(" to "); } Console.WriteLine(dest.ToString()); }
public Edge(Node n, double c) { this.destination = n; this.cost = c; }
/// <summary> /// This function will return a node from the nodeMap/dictonary. It will also create a node if you are trying /// to get a node which does not exist. This will prevent the graph from throwing NullReferenceExceptions /// </summary> /// <param name="position"></param> /// <param name="create"></param> /// <returns></returns> private Node GetNode(Vector2D position, bool create = false) { //Get node at the given position Node nodeAtPosition = this.nodeMap.Where(r => r.Key.x == position.x && r.Key.y == position.y).FirstOrDefault().Value; if (nodeAtPosition != null) return nodeAtPosition; //Are we allowed to create the node if it doesn't exist if (!create) return null; //Create a new node and add it to nodeMap. Node node = new Node(position); this.nodeMap.Add(position, node); return node; }