algorithm - 无法理解 A* 寻路算法,当两条路径似乎返回相同的 "length"但一条路径会向我发送完全错误的方向

标签 algorithm language-agnostic path-finding a-star heuristics

I am reading about A* pathfinding using heuristics and manhattan method我很难理解文章中某个特定位置的逻辑。

我卡在了下图的位置

enter image description here

为了更好地理解这里有一个引用

This time, when we check the adjacent squares we find that the one to the immediate right is a wall square, so we ignore that. The same goes for the one just above that. We also ignore the square just below the wall. Why? Because you can’t get to that square directly from the current square without cutting across the corner of the nearby wall. You really need to go down first and then move over to that square, moving around the corner in the process. (Note: This rule on cutting corners is optional. Its use depends on how your nodes are placed.)

并且 - 我已经突出显示了让我感到困惑的部分

That leaves five other squares. The other two squares below the current square aren’t already on the open list, so we add them and the current square becomes their parent. Of the other three squares, two are already on the closed list (the starting square, and the one just above the current square, both highlighted in blue in the diagram), so we ignore them. And the last square, to the immediate left of the current square, is checked to see if the G score is any lower if you go through the current square to get there. No dice. So we’re done and ready to check the next square on our open list.

所以作者假设现在左边的 F ( G + H ) 大于右边下面的 F。从逻辑上看,即使是 child 也会同意你应该走向红色,所以向下穿过蓝色的墙,但从数学上讲(除非我错过了一些明显的东西)我现在这样看

enter image description here

所以如果我用 C# 编写这个算法,我会被卡住,因为“现在这里”的左边和底部会返回相同的数字,60?我怎么知道进入哪个项目对我最有利?

即使在这种情况下,IMO 的数量仍将等于 60

  • 10 直接向左 + 50 (H)

  • 10 直接向下 + 50 (H)

enter image description here

我在这里错过了什么吗?我做错了什么?

最佳答案

G 成本是累积的。

从起点向东南方向花费 14。 从东南方格(你的“现在这里”方格)向南花费 10,这使得累计 G 花费为 10+14 = 24。

同样,从东南方 block (你的“现在这里”方 block )向西将花费 10 点 (G),这又给了我们 24 个点(因为我们已经支付了 14 个点才能到达那个方 block )。但是这个正方形已经在你的开放列表中,所以你检查你刚刚得到的结果是否更好。您的开放列表显示该方 block 的 G 为 10,因为 24 更差,所以您不更新它。 (加粗部分就是这个意思)

关于algorithm - 无法理解 A* 寻路算法,当两条路径似乎返回相同的 "length"但一条路径会向我发送完全错误的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25311902/

相关文章:

java - 从数组中删除连续元素的最有效方法? java

java - 比较方法的多个返回值

language-agnostic - GUID 是否 100% 都是唯一的?

math - float 学有问题吗?

java - 计算矩阵中非直连节点之间的距离

algorithm - 当我们之间有一些 block 时,如何找到最接近点的点! (在 2D 数组中 - 贪吃蛇游戏)

iOS应用程序中的C++算法

algorithm - 在求职面试中要求解决 NP 完全问题是否正确?

algorithm - 在 SPOJ 上寻找 MARTIAN 的 DP 解决方案的失败测试用例

algorithm - 如何在字母矩阵中找到单词