算法使用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实现
发布评论