游戏中的A*算法使用python实现

编程入门 行业动态 更新时间:2024-10-17 15:22:16

游戏中的A*<a href=https://www.elefans.com/category/jswz/34/1770096.html style=算法使用python实现"/>

游戏中的A*算法使用python实现

游戏中的算法少不了大明明鼎鼎A*算法,

但是要理解这样的算法,还是需要有一个简单的例子代码来不断地操作,

不断地变换参数,才能更加深入地了解它的过程。

OPEN = priority queue containing START
CLOSED = empty set
while lowest rank in OPEN is not the GOAL:current = remove lowest rank item from OPENadd current to CLOSEDfor neighbors of current:cost = g(current) + movementcost(current, neighbor)if neighbor in OPEN and cost less than g(neighbor):remove neighbor from OPEN, because new path is betterif neighbor in CLOSED and cost less than g(neighbor): ⁽²⁾remove neighbor from CLOSEDif neighbor not in OPEN and neighbor not in CLOSED:set g(neighbor) to costadd neighbor to OPENset priority queue rank to g(neighbor) + h(neighbor)set neighbor's parent to currentreconstruct reverse path from goal to start
by following parent pointers

算法的过程如上所述。

要把上面的代码变成一个python代码来测试&

更多推荐

游戏中的A*算法使用python实现

本文发布于:2024-02-26 21:31:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1703989.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   游戏中   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!