Pergunta

i have something like this.

---a-

aaa--

a----

---a-

b--a-

How can i reach all the a's from b in minimum steps? And how can i approach this with graph?

Foi útil?

Solução

a* algorithm might serve You well. It's vatiations are a common solution to finding shortest (least costly paths) in game development. As for graph representation define a structure called Node and Connection. you can use a std::vector for storing verticles and std::vector for connections (edges).

typedef struct 
{
  std::string name;
  //Other data that You need.
}Node;

typedef struct
{
  Node* nodeA;
  Node* nodeB;
  int travelCost;
  //other data that may come in handy
}Connection;

std::vector<Node> nodes;
std::vector<Connection> nodeConnections;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top