首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >A*寻路-我想我有它的伪代码,需要验证

A*寻路-我想我有它的伪代码,需要验证
EN

Stack Overflow用户
提问于 2012-02-17 06:35:52
回答 1查看 1.6K关注 0票数 1

他们说,将某人所说的话重复一遍,是验证概念基础(理解)的最好形式。所以,我一直在读关于A*的文章,并把它翻译成伪代码,我想我明白了。有没有人可以验证和/或给出这个实现是否可以工作的提示?

如果着急了,我很抱歉,我在工作中休息;)

代码语言:javascript
复制
openList.ClearTiles
closeList.clearTiles
path.clearTiles

openList.Add startTile

While openList.Count > 0 and PathFound = false
    activeTile = openList.GetTileWithLowestPathCost
    openList.remove activeTile
    closeList.add activeTile

    if targetTile.equals(activeTile)
       pathFound = true
    else
       for each activeTile.neighbors as nTile
           if nTile not in openList and not in closeList and IsMovable
              nTile.parent = activeTile
              nTile.hueristic = computeHeuristic
              nTile.movementCost = computeMovementCost
              nTile.pathCost = nTile.hueristic + nTile.movementCost

              openList.add nTile
           elseif isMovable = false
              closelist.add nTile
           endif
       next
    endif
endwhile

if pathFound = true        
   while activeTile.parent is not nothing
       path.insertAtZero activeTile
       activeTile = activeTile.parent
   endwhile
endif
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-17 06:49:47

你的伪代码有一个主要问题和一个小问题。

主要问题是:

当您找到nTile时,它可能已经在closedopen中,并且在您的实现中-您可以忽略它并跳过它。但是,如果它是封闭的或开放的,你应该检查你刚刚找到的路径成本可能比closedopen中的路径成本更好,如果是,从closed/open中删除它,然后用新的路径成本将它重新插入到open中。

次要问题:

有时有多个目标节点有一组目标节点,您正在寻找通向其中之一的路径。所以你可以选择if heuristicValue(activeTile) == 0 assuming the heuristic function is [admissible] 或者if activeTile is in targetStates,而不是if targetTile.equals(activeTile)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9320176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档