luizvao / a-star-java

Automatically exported from code.google.com/p/a-star-java
0 stars 0 forks source link

Bug in AreaMap#registerEdges() #4

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a new AreaMap with x=30, y=30
2. Create obstacles[][] array with the same dimensions
3. look for shortest path between 0,1 and 29,29

What is the expected output? What do you see instead?
It should return path object
It returns null only.

Please provide any additional information below.
This is due to a bug in AreaMap#registerEdges()

Please fix it !!

Original issue reported on code.google.com by moha...@gmail.com on 13 Apr 2014 at 8:35

GoogleCodeExporter commented 9 years ago
Change to this:

    private void registerEdges() {
        for (int x = 0; x < mapWith; x++) {
            for (int y = 0; y < mapHeight; y++) {
                Node node = map.get(x).get(y);
                if (!(y == 0))
                    node.setNorth(map.get(x).get(y - 1));
                if (!(y == 0) && !(x == mapWith - 1))
                    node.setNorthEast(map.get(x + 1).get(y - 1));
                if (!(x == mapWith - 1))
                    node.setEast(map.get(x + 1).get(y));
                if (!(x == mapWith - 1) && !(y == mapHeight - 1))
                    node.setSouthEast(map.get(x + 1).get(y + 1));
                if (!(y == mapHeight - 1))
                    node.setSouth(map.get(x).get(y + 1));
                if (!(x == 0) && !(y == mapHeight - 1))
                    node.setSouthWest(map.get(x - 1).get(y + 1));
                if (!(x == 0))
                    node.setWest(map.get(x - 1).get(y));
                if (!(x == 0) && !(y == 0))
                    node.setNorthWest(map.get(x - 1).get(y - 1));
            }
        }
    }

Original comment by rhma...@gmail.com on 16 Sep 2014 at 12:15