终于把A*算法弄明白了

前一段时间把资料整理好了,结果手上有活耽误了,不过还好做了个FLEX CHART的系统,感觉很爽,这两天又捡起了A*算法,今天用了一天的时间研究了一下A*算法的原理,终于弄明白怎么去实现了。呵呵,下一步挑战FLASH 3D。

感觉最好的学习办法就是用一个网格然后在上面把障碍物也标出来,自己去把每个点计算的过程和算法标出来。这样最直观了。

A*核心就是

曼哈顿算法:

H = 10*(abs(currentX-targetX) + abs(currentY-targetY))        //abs绝对值

对角线快捷

xDistance = abs(currentX-targetX)                                            //abs绝对值  

yDistance = abs(currentY-targetY)
if xDistance > yDistance
     H = 14*yDistance + 10*(xDistance-yDistance)
else
     H = 14*xDistance + 10*(yDistance-xDistance)
end if

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: