gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:15:40 25 4
gpt4 key购买 nike

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 tothe immediate right is a wall square, so we ignore that. The same goesfor the one just above that. We also ignore the square just below thewall. Why? Because you can’t get to that square directly from thecurrent 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 cuttingcorners is optional. Its use depends on how your nodes are placed.)

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

That leaves five other squares. The other two squares below thecurrent square aren’t already on the open list, so we add them and thecurrent square becomes their parent. Of the other three squares, twoare already on the closed list (the starting square, and the one justabove the current square, both highlighted in blue in the diagram), sowe ignore them. And the last square, to the immediate left of thecurrent square, is checked to see if the G score is any lower if yougo through the current square to get there. No dice. So we’re done andready 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com