Kaung Htet Kyaw

Kaung Htet Kyaw

  • NA
  • 61
  • 5.9k

Someone know about how to implement search method in Traveller.cs

Aug 22 2020 8:56 AM
Can someone know how to implement a search method in Traveller class? although it has the understandable comments to create, these things makes unclear for me about how to implement it.... Anyone who explain me thoroughly will be appreciated...
 
Here's the comments of the method
  1. public LinkedList Search(Waypoint start, Waypoint end,  
  2. Graph graph)  
  3. {  
  4.    // Create a search list (a sorted linked list) of search nodes  
  5.    // (I provided a SearchNode class, which you should instantiate  
  6.    // with Waypoint. I also provided a SortedLinkedList class)  
  7.    // Create a dictionary of search nodes keyed by the corresponding  
  8.    // graph node. This dictionary gives us a very fast way to determine  
  9.    // if the search node corresponding to a graph node is still in the  
  10.    // search list  
  11.    // Save references to the start and end graph nodes in variables  
  12.    // for each graph node in the graph  
  13.    // Create a search node for the graph node (the constructor I  
  14.    // provided in the SearchNode class initializes distance to the max  
  15.    // float value and previous to null)  
  16.    // If the graph node is the start node  
  17.    // Set the distance for the search node to 0  
  18.    // Add the search node to the search list  
  19.    // Add the search node to the dictionary keyed by the graph node  
  20.    // While the search list isn't empty  
  21.    // Save a reference to the current search node (the first search  
  22.    // node in the search list) in a variable. We do this because the  
  23.    // front of the search list has the smallest distance   
  24.    // Remove the first search node from the search list  
  25.    // Save a reference to the current graph node for the current search  
  26.    // node in a variable  
  27.    // Remove the search node from the dictionary (because it's no  
  28.    // longer in the search list)  
  29.    // If the current graph node is the end node  
  30.    //Display the distance for the current search node as the path  
  31.    // length in the scene (Hint: I used the HUD and the event  
  32.    // system to do this)  
  33.    // Return a linked list of the waypoints from the start node to  
  34.    // the end node. Uncomment the line of code below, replacing  
  35.    // the argument with the name of your current search node  
  36.    // variable; you MUST do this for the autograder to work  
  37.    // return BuildWaypointPath(currentSearchNode);  
  38.    // For each of the current graph node's neighbors  
  39.    // If the neighbor is still in the search list (use the  
  40.    // dictionary to check this)  
  41.    // Save the distance for the current graph node + the weight  
  42.    // of the edge from the current graph node to the current  
  43.    // neighbor in a variable  
  44.    // Retrieve the neighor search node from the dictionary  
  45.    // using the neighbor graph node  
  46.    // If the distance you just calculated is less than the  
  47.    // current distance for the neighbor search node  
  48.     // Set the distance for the neighbor search node to  
  49.     // the new distance  
  50.     // Set the previous node for the neighbor search node  
  51.     // to the current search node  
  52.     // Tell the search list to Reposition the neighbor  
  53.     // search node. We need to do this because the change  
  54.     // to the distance for the neighbor search node could  
  55.     // have moved it forward in the search list  
  56.     // didn't find a path from start to end nodes  
  57.     return null;  
  58. }  

Answers (1)