private void AddNodeCapsuleToOpenList(SortedDictionary<int, SortedDictionary<int, AStarNodeCapsule>> list, AStarNodeCapsule capsule) { int distanceToEnd = capsule.Priority; if (!list.ContainsKey(distanceToEnd)) { list[distanceToEnd] = new SortedDictionary<int, AStarNodeCapsule>(); } list[distanceToEnd][capsule.Node.ID] = capsule; }
/*Convenience methods*/ private void AddNodeCapsuleToClosedList(SortedDictionary<int, SortedDictionary<int, AStarNodeCapsule>> list, AStarNodeCapsule capsule) { if (capsule.ShortestDistance != null) { int distance = (int)capsule.ShortestDistance; if (!list.ContainsKey(distance)) { list[distance] = new SortedDictionary<int, AStarNodeCapsule>(); } list[distance][capsule.Node.ID] = capsule; System.Console.WriteLine("Closed node " + capsule.Node.ID); } }
private LinkedList<Node> GetRouteFromEndAStarNodeCapsule(AStarNodeCapsule endCapsule) { LinkedList<Node> route = new LinkedList<Node>(); AStarNodeCapsule currentCapsule = endCapsule; while (currentCapsule != null) { route.AddFirst(currentCapsule.Node); currentCapsule = currentCapsule.PreviousRouteNode; } route.RemoveFirst(); System.Console.WriteLine("New route:"); foreach(Node node in route) { System.Console.WriteLine(node.ID); } return route; }
private void RemoveNodeCapsuleFromOpenList(SortedDictionary<int, SortedDictionary<int, AStarNodeCapsule>> list, AStarNodeCapsule capsule) { list[(int)capsule.Priority].Remove(capsule.Node.ID); if (list[(int)capsule.Priority].Count == 0) { list.Remove(capsule.Priority); } }
private AStarNodeCapsule GetAdjacent(Dictionary<int, AStarNodeCapsule> capsuleMap, AStarNodeCapsule capsule, Edge edge) { if (edge.Node1 == capsule.Node) { return capsuleMap[edge.Node2.ID]; } else { return capsuleMap[edge.Node1.ID]; } }