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

如何设置网站icon磁力搜索引擎torrentkitty

如何设置网站icon,磁力搜索引擎torrentkitty,柳州做网站的公司有哪些,做网站就必须要开公司吗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.15wanjia.com/news/34530.html

相关文章:

  • 17网站一起做网店池尾商圈站长工具中文
  • 网站建设 环保 图片友情链接检查
  • 企业服务类型有哪些重庆快速排名优化
  • 做时时彩网站合法的吗购物网站哪个最好
  • php成品网站游戏推广一个月能拿多少钱
  • 哪个免费建站好百度快照入口
  • 做网站推广邢台营销推广技巧
  • 石家庄做外贸的网站建设厦门seo管理
  • thinkphp企业网站模板下载网站建设黄页免费观看
  • godday网站建设抖音推广引流平台
  • 个人可以做行业网站吗东莞优化排名公司
  • 中山哪里有做微网站的网络推广工作内容
  • 蚌埠网站排名关键词搜索引擎工具爱站
  • 厦门的服装商城网站建设嵌入式培训班一般多少钱
  • 网站建设作为seo自动点击排名
  • wordpress多站点是什么意思真正免费建站网站
  • 网站建设公司发展网络营销策划包括哪些内容
  • 做百度推广一定要有网站吗郑州网站开发公司
  • 笔记本做系统哪个网站好网站推广策划案
  • 郑州市网站建设怎么快速排名
  • 开发网站需要注意的安全问题什么是互联网推广
  • 可以看国外网站的dnsbilibili官网网页入口
  • 河南省两学一做网站网店推广方法有哪些
  • 有哪些做企业点评的网站seo排名点击
  • 自建网站工具百度关键词优化大师
  • 全面的网站建设东莞seo建站推广费用
  • 模板做网站新闻网站软文平台
  • 郑州整站网站优化网站优化公司
  • 电子商务网站建设课程设计代码网络营销方案设计
  • 外贸网站如何优化广州网站营销seo费用