Path Finding

StuffNET.AI


This implementation is not my work! I just used it, because it is so great! I wish i could refer to the origin of the code, but i don't know where i took it from.

The whole implementation is based on a generic node type. For example, when you want to calculate the shortest route on a map (GPS-navigation,...) you should use a crossroad class.
The AStar-method first needs a start node, of the type you mentioned. The second parameter is the target node. The third parameter needs a function in the following format:
public List<_your node type_> Name(_your node type_ node)
{
// Here you need to calculate all connected nodes to the node which is passed as a parameter.
// This mechanic allows very flexible use of the algorithm
}


The next parameter is a function you need to implement to calculate the distance between two given nodes.
public double Name(_your node type_ firstNode, _your node type secondNode)


Further more you can set the maximal amount of nodes, the maximal search depth and a threshold to determine whether the search is complete, although the current node still may has a small distance to the target node.
In some cases you want to make sure that two nodes have an additional amount of nodes between them; you can do so by passing a function with the following header:
public int Name(_your node type_ firstNode, _your node type_ secondNode)


After the algorithm calculates the shortest path for you, the method will return a List of nodes from the start to the end node (null, if no path was found).

Last edited Jul 21, 2012 at 11:50 AM by Xodem, version 1

Comments

No comments yet.