如何找到从a[x][y]到任意a[v][w]的最短路径?

How can i find the shortest path form a[x][y] to any a[v][w]?

本文关键字:最短路径 何找 任意      更新时间:2023-10-16

我有这样的东西

————

aaa——

,

————

b————

如何在最短的步长内到达b的所有a ?我怎么用图来表示呢?

一个*算法可能很适合你。这种变化是寻找游戏开发中最短(成本最低)路径的常见解决方案。对于图表示,定义一个称为Node和Connection的结构。你可以使用std::vector来存储顶点,std::vector来存储连接(边)。

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;