再译《A *路径搜索入门》之二

■路径评分

Path Scoring

计算出的路径时,确定要使用的方格的关键是下面的公式:

The key to determining which squares to use when figuring out the path is the following equation:

F = G + H

■这里

where

G =从起点A沿着生成的路径移动到一个给定的方形网格上运行成本。

G = the movement cost to move from the starting point A to a given square on the grid, following the path generated to get there.

H =从格子中给定方块移动到最终目的地,B点的估计的运行成本。这通常称为启发式,这可有点混乱。因为是一个猜测所以这样称呼。在找到路径之前,我们真的不知道实际的距离,因为各种各样的事情都在途中(墙,水等)。在本教程中给出一个计算H的方法,但在网络上你能找到许多计算H方法的其他文章。

H = the estimated movement cost to move from that given square on the grid to the final destination, point B. This is often referred to as the heuristic, which can be a bit confusing. The reason why it is called that is because it is a guess. We really don‘t know the actual distance until we find the path, because all sorts of things can be in the way (walls, water, etc.). You are given one way to calculate H in this tutorial, but there are many others that you can find in other articles on the web.

通过反复遍历开启列表,选择具有最小F值的方块来生成我们的路径。在本文中这个过程将有进一步更详细的描述。首先来仔细看看如何计算公式。

Our path is generated by repeatedly going through our open list and choosing the square with the lowest F score. This process will be described in more detail a bit further in the article. First let‘s look more closely at how we calculate the equation.

如上所述,G是从起始点移动到给定点所生成路径的运动成本。在这个例子中,我们将指定每个移动水平或垂直方成本为10,对角线移动成本为14。我们使用这些数字是因为斜角移动是2的平方根(不要害怕),是水平或垂直移动的大约1.414倍。我们使用10和14是为了简单起见。比例大致是正确的,又能避免计算平方根和小数。这不只是因为我们是愚笨的,不喜欢数学。采用这些数字是让计算机更快,太快了。你很快就会发现,如果你不使用这些捷径,路径搜索可能会很缓慢的。

As described above, G is the movement cost to move from the starting point to the given square using the path generated to get there. In this example, we will assign a cost of 10 to each horizontal or vertical square moved, and a cost of 14 for a diagonal move. We use these numbers because the actual distance to move diagonally is the square root of 2 (don‘t be scared), or roughly 1.414 times the cost of moving horizontally or vertically. We use 10 and 14 for simplicity‘s sake. The ratio is about right, and we avoid having to calculate square roots and we avoid decimals. This isn‘t just because we are dumb and don‘t like math. Using whole numbers like these is a lot faster for the computer, too. As you will soon find out, pathfinding can be very slow if you don‘t use short cuts like these.

由于我们计算G值是沿特定的路径给定的平方,该办法找出那个方块的父亲的G值,然后加10或14取决于它从父方格是正交(非对角线)还是对角线。需要这种方法将在本实施例进一步上变得明显一点,因为我们得到一个以上的方块。

Since we are calculating the G cost along a specific path to a given square, the way to figure out the G cost of that square is to take the G cost of its parent, and then add 10 or 14 depending on whether it is diagonal or orthogonal (non-diagonal) from that parent square. The need for this method will become apparent a little further on in this example, as we get more than one square away from the starting square.

H可以用各种方式估计。我们在这里使用的方法被称为曼哈顿方法,在这里计算从当前方块到目标方水平和垂直方向移动方块的总数,忽略对角运动,忽略可能在过程中的任何障碍。然后,我们将总数乘以10,我们的成本水平或垂直移动一格。这是(可能)被称为曼哈顿方法,因为它像计算城市街区的数量从一个地方到另一个地方,在那里你不能穿过块对角。

H can be estimated in a variety of ways. The method we use here is called the Manhattan method, where you calculate the total number of squares moved horizontally and vertically to reach the target square from the current square, ignoring diagonal movement, and ignoring any obstacles that may be in the way. We then multiply the total by 10, our cost for moving one square horizontally or vertically. This is (probably) called the Manhattan method because it is like calculating the number of city blocks from one place to another, where you can‘t cut across the block diagonally.

阅读本说明,您可能已经猜到了启发式仅仅是当前方格与目标之间的剩余距离的一个“像乌鸦飞似的”粗略的估计。不是这种情况。我们实际上试图估计沿路径的剩余距离(通常是更远)。越接近我们的估计是实际剩余距离,就会越快的算法。如果我们高估了这个距离,但是,它不能保证给我们的最短路径。在这样的情况下,我们有所谓的“不可接受启发式”。

Reading this description, you might guess that the heuristic is merely a rough estimate of the remaining distance between the current square and the target "as the crow flies." This isn‘t the case. We are actually trying to estimate the remaining distance along the path (which is usually farther). The closer our estimate is to the actual remaining distance, the faster the algorithm will be. If we overestimate this distance, however, it is not guaranteed to give us the shortest path. In such cases, we have what is called an "inadmissible heuristic."

从技术上讲,在这个例子中,曼哈顿方法是不可接受的,因为它稍稍高估了剩下的距离。但是我们会用也无妨,因为它是一个更容易理解我们的目的,因为它只是一个轻微的高估。在极少的情况下,得到的路径不是最短的,这将是近短。想了解更多?你你可以在这里(http://www.policyalmanac.org/games/heuristics.htm)找到方程和附加说明启发式。

Technically, in this example, the Manhattan method is inadmissible because it slightly overestimates the remaining distance. But we will use it anyway because it is a lot easier to understand for our purposes, and because it is only a slight overestimation. On the rare occasion when the resulting path is not the shortest possible, it will be nearly as short. Want to know more? You can find equations and additional notes on heuristics here.

F是G加H中的和。搜索的第一个步骤的结果可以从下面的说明中看出。在F,G和H的分数被写入在每个方格。正如在紧挨着开始方块右侧的方块上,F被打印在左上角,G印在左下方,而H显示在右下方。

F is calculated by adding G and H. The results of the first step in our search can be seen in the illustration below. The F, G, and H scores are written in each square. As is indicated in the square to the immediate right of the starting square, F is printed in the top left, G is printed in the bottom left, and H is printed in the bottom right.

[图3]

[Figure 3]

所以,让我们来看看其中的一些方块。在有字母的方块上,G = 10,这是因为它是在一个水平方向的距离起始方块仅一个方格。正方形紧邻上方,下方,及在起始方格的左边有10相同的G值,对角线方块有14个G值。

So let‘s look at some of these squares. In the square with the letters in it, G = 10. This is because it is just one square from the starting square in a horizontal direction. The squares immediately above, below, and to the left of the starting square all have the same G score of 10. The diagonal squares have G scores of 14.

H值是通过估计到红色目标方块的曼哈顿距离,仅移动水平和垂直方向,而忽略墙上那就是在计算方式。使用这种方法,方块上开始的直接右边3格是红格,为30。那么高于这个方块的方块的H值是4格距离(记住,只能水平移动和垂直)的一个H值40.你也许可以看到了为其他方块计算H值的方法。

The H scores are calculated by estimating the Manhattan distance to the red target square, moving only horizontally and vertically and ignoring the wall that is in the way. Using this method, the square to the immediate right of the start is 3 squares from the red square, for a H score of 30. The square just above this square is 4 squares away (remember, only move horizontally and vertically) for an H score of 40. You can probably see how the H scores are calculated for the other squares.

每个方格的F值,再次,只是通过加G和H一起计算。

The F score for each square, again, is simply calculated by adding G and H together.

(待续)

时间: 2024-11-11 10:25:41

再译《A *路径搜索入门》之二的相关文章

再译《A *路径搜索入门》之流畅版??

A *路径搜索入门 帕特里克·莱斯特发表于2003年10月8日下午8点33人工智能 如果您发现文中有错误或问题(丢失的影像或文件,受损代码,不正确的文本格式等),导致无法阅读它时,请联系编辑,以便能更正.感谢您帮助我们改善这个资源. 更新于2005年7月18日 这篇文章已被翻译成阿尔巴尼亚语,中文,法语,德语,葡萄牙语,俄语和西班牙语.欢迎其他的翻译.在这篇文章的末尾有联系的电子邮件地址. 对于初学者, A *(读A-星,译者注:老外读A-star)算法可能有些复杂.虽然在网上有很多解释A *算

再译《A *路径搜索入门》之一

※※※  外语不好凑合着看吧,呵呵  ※※※ A *路径搜索入门 A* Pathfinding for Beginners 帕特里克·莱斯特发表于2003年10月8日下午8点33人工智能 By Patrick Lester Published Oct 08 2003 08:33 PM in Artificial Intelligence 如果您发现本文中包含错误或问题,导致无法读取它(丢失的影像或文件,受损代码,不正确的文本格式等),请联系编辑,以便能更正.感谢您帮助我们改善此资源. If yo

A* Pathfinding for Beginners A*算法路径搜索入门

原始链接地址: http://www.gamedev.net/page/resources/_/technical/artificial-intelligence/a-pathfinding-for-beginners-r2003 Updated July 18, 2005 This article has been translated into Albanian, Chinese, French, German, Portuguese, Russian, and Spanish. Other

Bootstrap入门(二)栅格

Bootstrap入门(二)栅格 全局CSS样式--栅格 先引入本地的CSS文件(根据自己的文件夹,有不同的引入地址,我是放在一个新建的名为css的文件夹中) container 容器,栅格系统是依赖容器存在的 ... Bootstrap 提供的栅格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列. 栅格系统用于通过一系列的行(row)与列(column)的组合来创建页面布局.参数: 超小屏幕 手机 (<768px) 小屏幕 平板 (≥768px) 中等屏幕 桌面显示

[WebGL入门]十二,模型数据和顶点属性

注:文章译自http://wgld.org/,原作者杉本雅広(doxas),文章中如果有我的额外说明,我会加上[lufy:],另外,鄙人webgl研究还不够深入,一些专业词语,如果翻译有误,欢迎大家指正. 顶点属性的意思 上次的文章中,介绍了一下从着色器的生成,编译,到程序对象的生成和着色器的连接.这次,简单的说一下模型数据的定义和顶点属性的处理.另外,介绍一下根据模型数据生成VBO的方法.VBO的使用要比生成难理解一些,但是不要担心,后面会慢慢说明.接下来看一下顶点属性.顶点属性,说的简单点,

C语言快速入门教程(二)

C语言快速入门教程(二) C语言的基本语法 本节学习路线图: 引言: C语言,顾名思义就是一门语言,可以类比一下英语; 你要说出一个英语的句子需要:  单词  +  语法!  将单词按照一定的语法拼凑起来就成了一个英语句子了; C语言同样是这样,只不过单词可以理解为一些固定的知识点,而语法可以理解为算法(可以理解为解决问题的方法) 在这一节中我们就对固定知识点中的语言描述与数据存储进行解析! 1.C语言的基本元素 1.1  标识符 什么是标识符? 答:在C语言中,符号常量,变量,数组,函数等都需

Maven入门系列(二)--设置中央仓库的方法

原文地址:http://www.codeweblog.com/maven入门系列-二-设置中央仓库的方法/ Maven仓库放在我的文档里好吗?当然不好,重装一次电脑,意味着一切jar都要重新下载和发布. 下载的地址是中央仓库mvnrepository.com,当然,全球很多个仓库. 资源的坐标简称GVA 那么,现在如何修改maven的本地仓库路径呢? 关键在于maven文件夹的config下的settings.xml(E:\IDE\apache-maven-3.3.1\conf\settings

DWR入门实例(二)

DWR(Direct Web Remoting) DWR is a Java library that enables Java on the server and JavaScript in a browser to interact and call each other as simply as possible. Dwr能让在服务器端的java代码和浏览器客户端的javascript代码尽可能简单的相互调用. DWR is Easy Ajax for Java!  官网:http://d

DataVeryLite入门教程(二) Entity篇

DataVeryLite 是基于.net 4.0的数据库持久化ORM框架. 目前支持的数据库有Sqlserver,Mysql,Oracle,Db2,PostgreSql,Sqlite和Access. 最好先阅读DataVeryLite入门教程(一) 配置篇,然后再阅读本篇.如果你觉得麻烦也可以跳过. Entity是ORM中的核心对象之一,一个继承Entity的对象对应于数据库中的一个表. Entity提供丰富的API对表中的单条数据进行操作. 比如根据id或其他条件,加载,删除,插入,更新和部分

SIP入门(二):建立SIPserver

在我的上一篇文章中已经介绍怎样通过SIP软电话直接通话,可是假设须要支持很多其它用户互相通话,同一时候基于安全考虑,须要对用户帐户登录进行验证控制,这些情况下就须要建立SIPserver. SIPserver的作用: 呼叫控制和处理功能.业务提供/支持功能.用户管理功能.协议处理功能.路由处理.接入认证.计费信息採集.操作维护/网管功能.互通功能.安全功能(可选).黑白名单功能.拥塞控制功能(可选). 建立SIPserver的条件: * 一台计算机,作为server: * server通常须要拥