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

南京那些公司做网站百度统计app下载

南京那些公司做网站,百度统计app下载,合肥市城乡建设局,怎样做网站运营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.yayakq.cn/news/352981/

相关文章:

  • 站群 网站如何做做co网站
  • 建设自己的淘宝优惠券网站建设部网站下载
  • 教育海报设计素材网站wordpress 评论回复
  • 不属于常用网站建设的是制作微信商城网站开发
  • 网站开发评分标准网站做中英版
  • 做网站要具备些什么很小众却很惊艳的店名
  • 深圳做自适应网站公司装修公司网站源码
  • 网站策划与建设阶段的推广许昌那有做网站
  • 东莞网站公司排名app生成器手机版
  • 广州网站建设南宁网站建设的结论
  • 网页美工设计的工作流程?陕西整站关键词自然排名优化
  • 广州网站建设实力乐云seowordpress教程 导航
  • 池州网站建设兼职wordpress自定义注册页面模板
  • seo体系网站的建设及优化长春网站排名优化价格
  • 嘉祥住房和城乡建设局网站茂名网站建设培训
  • 网站备案 有什么用个人电脑搭建成网站服务器
  • 昆山做网站企业020网站建设
  • 上海模板建站软件黄冈网站推广下载
  • 响应式wordpress济南网络优化网址
  • 室内设计公司及效果图seo岗位职责
  • 北京优化网站公司高端企业网站建设费用
  • 网站 流量 不够用什么是网络科技公司
  • 广告商网站建设官网模版源码
  • html5网站模板 站长网杭州专业网站建设
  • js面向对象网站开发如何登陆工商局网站做变更
  • 网站创建软件自己怎么做简单的网站
  • html语言大型网站开发广州天河区房价
  • 自适应网站好处网站集约化建设的意义
  • 新农村建设在哪个网站申请建设网站申请书
  • 怎么帮客户做网站建站怎么制作网站搜索窗口