Yonaba / Jumper

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

bug with JPS and ORTHOGONAL mode? #42

Closed takaaptech closed 9 years ago

takaaptech commented 9 years ago

Hi, Thank for awesome Jumper! I think we have a bug with JPS and ORTHOGONAL combo? If i change JPS to ASTAR, the path is found.

Thanks!

-- Usage Example
-- First, set a collision map
local map = {
    {1,0,1,0,0},
    {0,0,0,0,0},
    {1,0,0,0,0},
    {0,0,0,0,0},
}
-- Value for walkable tiles
local walkable = 0

-- Library setup
local Grid = require ("zgame.jumper.grid") -- The grid class
local Pathfinder = require ("zgame.jumper.pathfinder") -- The pathfinder lass

-- Creates a grid object
local grid = Grid(map) 
-- Creates a pathfinder object using Jump Point Search
local myFinder = Pathfinder(grid, 'JPS', walkable) 
myFinder:setMode ('ORTHOGONAL')

-- Define start and goal locations coordinates
local startx, starty = 1,1
local endx, endy = 2,2

-- Calculates the path, and its length
local path = myFinder:getPath(startx, starty, endx, endy)
if path then
  print(('Path found! Length: %.2f'):format(path:getLength()))
    for node, count in path:nodes() do
      print(('Step: %d - x: %d - y: %d'):format(count, node:getX(), node:getY()))
    end
end
Yonaba commented 9 years ago

Hi, @takaaptech,

Much thanks for the kind words. Really like you are enjoying using Jumper.

I'd like to point out a few things... Actually, from your example, I cannot really say what is the issue. Maybe you can use images to let me know what kind of path do you get and what is the result you were expecting. But I somehow suspect you are mentioning a known issue, #20. Thing is, the JPS algorithm was not devised for orthogonal mode as-is. Since the algorithm itself takes advantages of heading diagonal first-moves over orthogonal moves, eliminating adjacent (diagonal) moves is a bit trickier than it looks and need some work. I already field this as an issue and I'll try my best to fix in in the next version of the library.

Second, from the syntax you are using, I can notice you are using the very last version of Jumper, which is untagged, in-development and not stable at all. I'll strongly recommend to use instead the latest stable, which is 1.8.1 as of this writing. Documentation is available here.

Regards, Roland.

takaaptech commented 9 years ago

Hi @Yonaba! I think issue #20 is as same as my bug. Using JPS i can not move the red item from (1,1) to (2,2), but ASTAR can. So should i use ASTAR for my game? I just need to check path for item moving around a board, like bellow:

screen shot 2015-09-06 at 11 20 54 pm

Thank so much!

Yonaba commented 9 years ago

For such a board, performance is not much of an issue. Indeed, you can definitely go ahead with ASTAR, it will be fast enough!

takaaptech commented 9 years ago

OK i got it, thank you so much!