当前位置: 首页 > news >正文

如何设置网站icon百度怎么优化网站关键词

如何设置网站icon,百度怎么优化网站关键词,建设银行个人登录网站,自己做交易网站A*(A-star)是一种图遍历和寻路算法,由于其完整性、最优性和最佳效率,它被用于计算机科学的许多领域。给定一个加权图、一个源节点和一个目标节点,该算法将找到从源到目标的最短路径(相对于给定的权重&#…

A*(A-star)是一种图遍历和寻路算法,由于其完整性、最优性和最佳效率,它被用于计算机科学的许多领域。给定一个加权图、一个源节点和一个目标节点,该算法将找到从源到目标的最短路径(相对于给定的权重)。

算法过程:遍历方向为从竖直向上沿顺时针方向。

1.首先计算开始节点的G,H,F值,将开始节点放入检测列表中。

2.将检测列表中的所有点按到目标所需的成本的估计值F排序,选择F最小的节点作为当前节点。

3.将当前点从检测列表中移除,加入到已检测列表中。

4.计算当前点周围的八个点G,H,F值,将不包含在检测列表中的点加入到检测列表。

5.重复2,3,4,直到找到目标点。

注:

F = g (n)+ h(n)

gn) 是从起始节点到 n 的路径的成本,hn) 是一个启发式函数,用于估计从 n 到目标的最便宜路径的成本。

代码实现:

改造路径点数据类:

public class DataNode
{public Vector2Int pos;public DataNode parent;//A*使用public int gCost = 999999999;public int hCost;public int fCost;public DataNode(Vector2Int pos, DataNode parent){this.pos = pos;this.parent = parent;}//A*使用计算Fpublic void CalculateFCost(){fCost = gCost + hCost;}
}

算法类:

public class AStar : FindPathAlgorithm
{public AStar(int[,] mapData, int xCount, int zCount) : base(mapData, xCount, zCount){}public override List<Vector2Int> FindPath(Vector2Int startPos, Vector2Int goalPos){DataNode dataNode = this.AStarFind(startPos, goalPos);if (dataNode == null){Debug.LogError("寻路有误,请检查参数是否正确");return null;}return Utils.GetPath(dataNode);}DataNode AStarFind(Vector2Int startPos, Vector2Int goalPos){//存储要检测的点List<DataNode> frontier = new List<DataNode>();//存储已经检测的点List<Vector2Int> reached = new List<Vector2Int>();DataNode startNode = new DataNode(startPos,null);startNode.gCost = 0;startNode.hCost = CalculateDistanceCost(startPos, goalPos);startNode.CalculateFCost();frontier.Add(startNode);while (frontier.Count > 0){DataNode currentNode = GetLowestFCostNode(frontier);if (currentNode.pos == goalPos){return new DataNode(goalPos, currentNode.parent);}frontier.Remove(currentNode);reached.Add(currentNode.pos);List<DataNode> neighbors = GetNeighbors(currentNode.pos, reached);foreach (DataNode neighbourNode in neighbors){int tentativeGCost = currentNode.gCost + CalculateDistanceCost(currentNode.pos, neighbourNode.pos);if (tentativeGCost < neighbourNode.gCost){neighbourNode.parent = currentNode;neighbourNode.gCost = tentativeGCost;neighbourNode.hCost = CalculateDistanceCost(neighbourNode.pos, goalPos);neighbourNode.CalculateFCost();if (!frontier.Contains(neighbourNode)){frontier.Add(neighbourNode);}}}}return null;}List<DataNode> GetNeighbors(Vector2Int current, List<Vector2Int> reached){List<DataNode> neighbors = new List<DataNode>();for (int i = 0; i < Utils.pointDir.Count; i++){Vector2Int neighbor = current + Utils.pointDir[i];if (this.IsCanAdd(neighbor, reached)){neighbors.Add(new DataNode(neighbor,null));}}return neighbors;}bool IsCanAdd(Vector2Int current, List<Vector2Int> reached){if (reached.Contains(current))return false;if (current.x >= 0 && current.y >= 0 && current.x < xCount && current.y < zCount){//如果是障碍物,则不能被Addif (this.mapData[current.y, current.x] == 1){return false;}return true;}return false;}private int CalculateDistanceCost(Vector2Int a, Vector2Int b){return Mathf.Abs(a.x - b.x) + Mathf.Abs(a.y - b.y);}private DataNode GetLowestFCostNode(List<DataNode> pathNodeList){DataNode lowestFCostNode = pathNodeList[0];for (int i = 1; i < pathNodeList.Count; i++){if (pathNodeList[i].fCost < lowestFCostNode.fCost){lowestFCostNode = pathNodeList[i];}}return lowestFCostNode;}
}

结果:

参考链接:

A* 算法简介 (redblobgames.com)

A* 搜索算法 - 维基百科,自由的百科全书 (wikipedia.org)

A* Pathfinding (E01: algorithm explanation) - YouTube

http://www.tj-hxxt.cn/news/102264.html

相关文章:

  • 最近国内色情网站做的最好的是哪个长沙网络推广
  • 知名网站域名友妙招链接怎么弄
  • 企业网站建设管理系统上海优化公司选哪个
  • 别人不能注册我的wordpress站东莞网站快速排名提升
  • asp.net做网站源代码营销型网站分为哪几种
  • 修机械师怎么做我小样网站角仰望百度站长平台链接
  • 无限容量网站sem竞价专员
  • 动漫毕业设计作品网站网站开发月薪多少钱
  • 沧县网站制作seo上首页
  • 8月4日建设部网站通报网站如何做推广
  • php 政府网站源码百度热词
  • 网站做的好不好看什么海外网络推广
  • 网站开发与发布广西网站seo
  • 永康网站建设什么软件推广效果好
  • 去哪找网站建设公司seo助力网站转化率提升
  • 有哪些网站是用php做的在百度上打广告找谁推广产品
  • 广告公司寮步网站建设哪家好市场营销七大策略
  • 上海网站建设价格表怎么给产品找关键词
  • 沙特政府建设部网站产品推广运营的公司
  • 网站报价书公司网站推广
  • 网站被降权会发生什么扬州网站seo
  • 成都网站建设四易维达打开浏览器直接进入网站
  • 提供网站制作百度一下进入首页
  • 南昌网站seo外包自动推广软件免费
  • 用网站做宣传的费用网络营销有哪些内容
  • 网站开发与服务合同范本广州百度竞价外包
  • 个人可以做导航网站吗国外域名注册
  • 环球网今日疫情消息镇江网站关键字优化
  • 网站建设过程中应该注意的事项有想建立自己的网站怎么建立
  • 苏州运营推广网站建设二十条优化措施全文