Yonaba / Jumper

Fast, lightweight and easy-to-use pathfinding library for grid-based games
http://yonaba.github.io/Jumper
MIT License
611 stars 123 forks source link

Path fails to return when starting from an unwalkable location #2

Closed vitalitymobile closed 11 years ago

vitalitymobile commented 11 years ago

Hi Yonaba, I am using Jumper in my project and setup the map like bellow. But when i try to move gem from 5,3 to 4,3 (that i think it nearby and possible to move) it show can not move. Can you check it?

Thanks!

local Jumper = require 'Jumper.init'
local map = {
    {0,1,1,1,0,1,1},
    {1,1,1,1,1,1,1},
    {0,0,1,0,1,1,1},
    {1,1,1,1,1,1,1},
}

local walkable = 0
local postProcess = false
local pather = Jumper(map,walkable,postProcess)
local sx,sy = 5,3
local ex,ey = 4,3
print('Hello Jumper! from Gideros')
local path = pather:getPath(sx,sy,ex,ey)
if path then
  print(('Path from [%d,%d] to [%d,%d] was : found!'):format(sx,sy,ex,ey))
  for i,node in ipairs(path) do
    print(('Step %d. Node [%d,%d]'):format(i,node.x,node.y))
  end
else
    print(('Path from [%d,%d] to [%d,%d] was : not found!'):format(sx,sy,ex,ey))
end  
Yonaba commented 11 years ago

Hi @vitalitymobile, Well, that's a little issue I planned to fix, since it occurs on very specific cases (more precisely when the first step goes from an unwalkable node) but for some reasons I lost track of it on my to-do list. Thanks poiting it out, though. I'll push a commit as soon as I reach my workstation.

PS: Looking at the example you provided, it seems you're using an outdated version of Jumper. I strongly recommend to move to the latest stable (1.8.0). They have been a few changes. You can take a look at the Readme for usage examples and verbose explanations.

Thanks for your feedback.

vitalitymobile commented 11 years ago

Thanks for your quick reply. Another question, In each move step, do I have to call an init Jumper like this:

self.pather = Jumper(map,self.walkable,self.postProcess) local path = self.pather:getPath(sx,sy,ex,ey);

Or is there any way to simple call getPath when need ( ofcourse the map logic change before call)

Yonaba commented 11 years ago

Unless I totally missed what you meant saying map logic change before call, I'd rather say no, you don't need this at all. You might want to explain the idea a little more, though. Thanks.

vitalitymobile commented 11 years ago

Yes, sorry for my bad of English In my game, after user make a correct move, i update map table, and when user going to another move, i must check for path, so my question is in this case, do i have to call self.pather = Jumper(map,self.walkable,self.postProcess) again

or just call local path = self.pather:getPath(sx,sy,ex,ey);

Thanks!

Yonaba commented 11 years ago

Updating the map won't require to init again a new pathFinder instance, as in the code, while processing a path computation, the pathFinder will always check for each node being expanded if it is walkable or not. On the fly. That's a feature added as of v1.6.3. So, well, you won't need to init anything again if you're using this version, or more recent. Just keep calling getPath.

srdjan-m commented 11 years ago

I would like to add that Jumper works deadly fast! I the game that I am currently working on I am calling getPath three times per second and there is no visible slowdown at all. Great work!

vitalitymobile commented 11 years ago

Thanks Yonaba, now I understand it! Please fix the bug soon so I can use it in my next game! Can I quick fix this by set the starting node to walkable?

Yonaba commented 11 years ago

Yes, making the first node walkable would work. But that might not be necessary. Try the latest v1.8.1 Well, you might want to take a look at the Readme, since it seems you're using an outdated version, newer updates might break your code. Let me know if there is any problem.

vitalitymobile commented 11 years ago

It works like a charm now! Thanks you so much Yonaba!