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

扁平化配色方案网站wordpress数据库怎么替换链接

扁平化配色方案网站,wordpress数据库怎么替换链接,网站开发设计流程论文,电子商务平台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/183031.html

相关文章:

  • 成都做营销型网站建设有专门做网站的吗
  • 在线制作二维码网站有哪些好的网站制作公司
  • 珠海易注册网站公司网站宣传设计方案
  • 主备网站服务器自动切换 win2003做网站跟网站设计的区别
  • 佛山本科网站建设百度怎么推广广告
  • 公司做一个网站内容如何设计方案适合手机上做的兼职
  • 网站是用什么做的吗网站注册空间
  • 建设信用卡中心网站首页游戏推广员是违法的吗
  • 网站备案有什么作用2014最新网站模板-网页模板免费下载-风格吧
  • 企业设计网站公司排名wordpress专业
  • 网站能实现什么功能28商机网创业项目
  • 刚开今天新开传奇网站免费咨询服务合同范本免费版
  • 成都网站建设哪些公司好网站网页设计基本理论
  • 网站如何做攻击防护常熟网站建设书生商友
  • 西安的网站设计与制作首页中国核工业第五建设有限公司官网
  • 洛阳网站seo织梦模板库
  • 什么网站做电子元器件微信怎么做公众号
  • 整站优化该怎么做网站建设公司 经营资质
  • 滁州市建设银行网站少儿编程哪个机构比较好
  • 网页制作工具可以发布网站吗html网站开发视频
  • 郑州企业网站优化公司管理网页
  • 网站交换链接如何实施公众号兼职网站开发
  • 织梦cms怎么搭建网站河南郑州天气预报15天
  • 养生网站建设论文网站底色什么颜色好看
  • 一个网站用多少数据库表中国各省旅游网站建设分析
  • 零基础学网站开发网络营销logo
  • 福州企业网站建设开发公司五证
  • html做网站的毕业设计万远翔网站建设
  • xx网站建设策划方案做普工招聘网站
  • 网站设计协议移动端app下载