TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kaung Htet Kyaw
NA
66
6.3k
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
public
LinkedList Search(Waypoint start, Waypoint end,
Graph graph)
{
// Create a search list (a sorted linked list) of search nodes
// (I provided a SearchNode class, which you should instantiate
// with Waypoint. I also provided a SortedLinkedList class)
// Create a dictionary of search nodes keyed by the corresponding
// graph node. This dictionary gives us a very fast way to determine
// if the search node corresponding to a graph node is still in the
// search list
// Save references to the start and end graph nodes in variables
// for each graph node in the graph
// Create a search node for the graph node (the constructor I
// provided in the SearchNode class initializes distance to the max
// float value and previous to null)
// If the graph node is the start node
// Set the distance for the search node to 0
// Add the search node to the search list
// Add the search node to the dictionary keyed by the graph node
// While the search list isn't empty
// Save a reference to the current search node (the first search
// node in the search list) in a variable. We do this because the
// front of the search list has the smallest distance
// Remove the first search node from the search list
// Save a reference to the current graph node for the current search
// node in a variable
// Remove the search node from the dictionary (because it's no
// longer in the search list)
// If the current graph node is the end node
//Display the distance for the current search node as the path
// length in the scene (Hint: I used the HUD and the event
// system to do this)
// Return a linked list of the waypoints from the start node to
// the end node. Uncomment the line of code below, replacing
// the argument with the name of your current search node
// variable; you MUST do this for the autograder to work
// return BuildWaypointPath(currentSearchNode);
// For each of the current graph node's neighbors
// If the neighbor is still in the search list (use the
// dictionary to check this)
// Save the distance for the current graph node + the weight
// of the edge from the current graph node to the current
// neighbor in a variable
// Retrieve the neighor search node from the dictionary
// using the neighbor graph node
// If the distance you just calculated is less than the
// current distance for the neighbor search node
// Set the distance for the neighbor search node to
// the new distance
// Set the previous node for the neighbor search node
// to the current search node
// Tell the search list to Reposition the neighbor
// search node. We need to do this because the change
// to the distance for the neighbor search node could
// have moved it forward in the search list
// didn't find a path from start to end nodes
return
null
;
}
Reply
Answers (
1
)
Genetic Algorithms for AI
how to convert asp file into asp.net