Search code examples
c#algorithmdata-structuresgrapha-star

Structure of Astar (A*) graph search data in C#


How do you structure you graphs/nodes in a graph search class? I'm basically creating a NavMesh and need to generate the nodes from 1 polygon to the other. The edge that joins both polygons will be the node.

alt text

I'll then run A* on these Nodes to calculate the shortest path. I just need to know how to structure my classes and their properties?

I know for sure I wont need to create a fully blown undirected graph with nodes and edges.


Solution

  • All you need for A* is the ability to take a node and from it efficiently extract a list of its neighbouring nodes. If you already have some data structure that is keeping track of what edges are in what polygons then that seems straightforward; just write a function that takes an Edge and returns IEnumerable<Edge> by extracting that data out of your existing data structure.