• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

lattejed/a-star-lua: A clean, simple implementation of the A* pathfinding algori ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

lattejed/a-star-lua

开源软件地址(OpenSource Url):

https://github.com/lattejed/a-star-lua

开源编程语言(OpenSource Language):

Lua 100.0%

开源软件介绍(OpenSource Introduction):

A* for Lua

A clean, simple implementation of the A* pathfinding algorithm for Lua.

This implementation has no dependencies and has a simple interface. It takes a table of nodes, a start and end point and a "valid neighbor" function which makes it easy to adapt the module's behavior, especially in circumstances where valid paths would frequently change.

The module automatically caches paths which saves CPU time for frequently accessed start and end nodes. Cached paths can be ignored by setting the appropriate parameter in the main function. Cached paths can be purged with the clear_cached_paths () function.

Usage example

-- this function determines which neighbors are valid (e.g., within range)
local valid_node_func = function ( node, neighbor ) 

	local MAX_DIST = 300
		
	-- helper function in the a-star module, returns distance between points
	if astar.distance ( node.x, node.y, neighbor.x, neighbor.y ) < MAX_DIST then
		return true
	end
	return false
end

local ignore = true -- ignore cached paths

local path = astar.path ( start, end, all_nodes, ignore, valid_node_func )

if path then
	-- do something with path (a lua table of ordered nodes from start to end)
end

Notes

This assumes that nodes are objects (tables) with (at least) members "x" and "y" that hold the node's coordinates.

node = {}
node.x = 123
node.y = 456
node.foo = "bar"



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap