TLpath, A* pathfinding for Love

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

TLpath, A* pathfinding for Love

Post by Taehl »

I hope this will be handy. TLpath is a fast, efficient pathfinder which I've built to be as flexible as possible. But despite my best efforts, pathfinding isn't a simple thing, so this isn't completely a fire-and-forget solution. To implement it in a given game, you'll need to add path nodes and (likely) give it an appropriate g-function. But other than that, it should be pretty easy to get along with. It even does its work in a separate thread, so your game can continue working as normal while it finds paths for you. It comes with a simple demo showing off how fast it is and how to use it. So let's see some AI in your games!

Download: Here
Documentation/wiki: TLpath

Comments? Critique? Accolades? Need help using it? This is the place for it.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: TLpath, A* pathfinding for Love

Post by Robin »

Looks interesting.
Taehl wrote:Accolades?
{, }
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: TLpath, A* pathfinding for Love

Post by kikito »

Image
When I write def I mean function.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: TLpath, A* pathfinding for Love

Post by vrld »

The demo doesn't work for me:

Code: Select all

Error: [string "main.lua"]:174: attempt to index field '?' (a nil value)
Also set[GH]function feel akward. You can serialize functions (without upvalues) using string.dump:

Code: Select all

function foo() print('bar') return 'baz' end
serialized = string.dump(foo) --> function bytecode
magic = loadstring(serialized)
print( magic() )
Edit: Wait, it worked. Then it failed on line 143 (attempt to index local 'b').
Sometimes love locks completely (deadlock somewhere?)
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: TLpath, A* pathfinding for Love

Post by Taehl »

I have a .zip instead of a .love file to make it that much easier to open up and get the files from - it's not a game in and of itself.

I have no idea what your problems are from, vrld. I don't experience those. I've updated the download, which may help. set[GH]function are for convenience. If you don't want to use them, you can go rewrite the gScore and hScore functions in TLpath.lua (lines 78 and 80).
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: TLpath, A* pathfinding for Love

Post by vrld »

Taehl wrote:I've updated the download, which may help.
That fixed it. :3
Taehl wrote:set[GH]function are for convenience.
They would be more convenient if I could pass true lua functions instead of strings, possibly alongside with some custom data:

Code: Select all

TLpath.setGfunction(function(a,b, my_data)
    local function reachable() ... stuff with my_data ... end
    return reachable() and math.abs(b.x - a.x) + math.abs(b.y - a.y)
end, walls)
That would feel less hackish to me and allow the editor to highlight the code
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Re: TLpath, A* pathfinding for Love

Post by Lap »

Straight into my game whenever vrld's suggestion gets added. Well done.
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: TLpath, A* pathfinding for Love

Post by ishkabible »

can you make a Dijkstra's path finding option? i have an un-encapsulated implementation if you want to look at it. it names nodes by string and lets you build your network. with a bit of modification to the NewNode function it could store whatever data it needed(like coordinates). the benefit of Dijkstra's algorithm here is you don't need a uniform plane for it to work. say you want to put a few rocks in the way, no biggy you simply wont put a node there.
Attachments
DijtrasAlgorithim.lua
(2.88 KiB) Downloaded 382 times
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: TLpath, A* pathfinding for Love

Post by Taehl »

vrld wrote:They would be more convenient if I could pass true lua functions instead of strings, possibly alongside with some custom data:
I'd love to offer that, but you can only send strings and numbers (and maybe bools?) to threads, and the resulting functions would have to have the right name or else it wouldn't work. The best I can do is send code as a string and execute it on the other side.
ishkabible wrote:it names nodes by string and lets you build your network. with a bit of modification to the NewNode function it could store whatever data it needed(like coordinates). the benefit of Dijkstra's algorithm here is you don't need a uniform plane for it to work. say you want to put a few rocks in the way, no biggy you simply wont put a node there.
I don't see why you can't do that in A*? My demo only uses a grid for half of the maps just to show it can be done. Technically you don't even need to place and g-score nodes by coordinates, if you have a different method.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: TLpath, A* pathfinding for Love

Post by vrld »

Taehl wrote:I'd love to offer that, but you can only send strings and numbers (and maybe bools?) to threads, and the resulting functions would have to have the right name or else it wouldn't work.
vrld wrote:You can serialize functions (without upvalues) using string.dump:

Code: Select all

function foo() print('bar') return 'baz' end
serialized = string.dump(foo) --> function bytecode
magic = loadstring(serialized)
print( magic() )
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Post Reply

Who is online

Users browsing this forum: No registered users and 222 guests