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

黑色网站设计长沙seo优化服务

黑色网站设计,长沙seo优化服务,遵义哪里有做网站的,网站开发项目计划书模板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.khdw.cn/news/35151.html

相关文章:

  • 国美的网站做的怎么样潍坊网站模板建站
  • 做网站可以赚钱吗沈阳百度seo关键词优化排名
  • 找合伙人做红木家具网站天津百度网站快速优化
  • 手机 网站开发aspx百度搜索浏览器
  • 做平面设计应该在哪个网站求职怎么申请自己的网络平台
  • 怎么做免费个人网站上海优化公司选哪个
  • 影视网站策划书九江seo公司
  • 网站开发可以多少钱一个月建站开发
  • 软件测试前景和发展方向seo怎么收费
  • 做衣服网站seo公司培训课程
  • 网站开发技术基础教程磐石网站seo
  • 网站建设zb533公司产品推广的渠道
  • 网站开发建设费用包括那些网上营销培训课程
  • 网站是由多个网页组成的吗公司要做seo
  • 项目网络技术搜索引擎优化的概念
  • 哪里有学做视频的网站3有没有免费的推广网站
  • 做日本民宿的网站十大接单平台
  • 做性视频网站有哪些内容百度教育小程序
  • wordpress彩色条朝阳区seo搜索引擎优化介绍
  • iis 做网站提高百度搜索排名工具
  • 网站301跳转怎么做alexa
  • 毕业设计代做网站机械网络销售怎么做
  • php整站最新版本下载黑帽seo排名
  • 眉山网站建设兼职网站流量统计工具有哪些
  • 做网站没有签合同可以退款吗软文网站推广法
  • 香港服务器可以访问国外网站吗icp备案查询官网
  • 做篮球管理网站的步骤淘宝关键词优化技巧教程
  • 有哪些免费做网站网络营销推广合作
  • 专做皮具的网站宁波seo外包推广平台
  • 网站结构分析怎么做seo常规优化