Bug in A* library (SOLVED, not bug)

#1

I have tried building the library shared at https://github.com/selimanac/defold-astar

I have added basic shape rendering to visualize the main.script content and have found that the library
is returning a faulty result for the example given. I would share my updated project file but I also see the library has no license specified so not sure it’s legal to do so.

Anyone know what’s going on with it?

EDIT: I see it shows the MIT license here but without the full license text: https://defold.com/assets/apathfinding/ Not sure this is enough.

1 Like

#2

@selimanac is the author. He’ll hopefully be able to help you.

There should be a license file in the GitHub repo but as you say it is missing. @selimanac you need to add that. https://docs.github.com/en/github/building-a-strong-community/adding-a-license-to-a-repository

1 Like

#3

I’m using this lib for my side projects and a few other Defold devs are using too. Afaik, no one reported a faulty results before. So I’m not sure what is wrong going on here. Maybe there is a mistake on the main example, but could you please explain what is wrong?

Also, I highly recommend that you can check out the visual examples here. They might be very useful for handling tiles and visualizing:

This lib is based on MicroPather. Original license info can be seen here:

1 Like

#4

Sure, I packaged up the example project with modifications to visualize the example path. As shown, the start location is drawn with a diamond and the end location is drawn as a octagon. The walls are rectangles. The start location appears to be within a wall when the path calculation begins (strange) and it cuts through two walls on its path to the end location. I might be doing something wrong though (highly likely) but I tried implementing the library into my game and the same wall cutting behavior is occurring. BTW: Feel free to use the visualization code if you think it will help people understand the library better. It appears to open a blank window and print the tile path results to console as is.

defold-astar-master.zip (5.4 MB)

0 Likes

#5

I’m going to take a look at your project when I got free time. Meanwhile I still recommend you to check out the examples.

Feel free to contribute the community and release your example on Github. It would be great actually. :slight_smile:

0 Likes

#6

I loaded up the examples and I can’t see any obvious problems with them. I’ll analyze the code here to try and figure it out.

0 Likes

#7

I’m still looking, but one quick find; lua tables start with 1 not 0.
In your case, it has to be:

if (world[y * map_width + x + 1] == 0) then

Edit: This is the proper loop for the table, it fix the visual appearance of the rectangles:

     for y = 0, map_height - 1 do
        for x = 0, map_width - 1 do
            if (world[y * map_width + x + 1] == 0) then
                draw_square(vmath.vector3(x * 32 + 16, y * 32 + 16, 0), 30)
            end
        end
    end
3 Likes

#8

Ah thanks! I’m still getting used to Lua. I’m coming from a Java/C background so I’m so used to 0-indexed data structures I hadn’t thought of this. The example works perfectly now :slight_smile:

2 Likes