com.badlogic.gdx.ai.pfa.GraphPath Java Examples
The following examples show how to use
com.badlogic.gdx.ai.pfa.GraphPath.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexedAStarPathFinderTest.java From gdx-ai with Apache License 2.0 | 6 votes |
@Test public void searchNodePath_WhenDestinationUnreachable_ExpectedNoOuputPathFound () { // @off - disable libgdx formatter final String graphDrawing = ".....#....\n" + ".....#....\n" + ".....#...."; // @on - enable libgdx formatter final MyGraph graph = createGraphFromTextRepresentation(graphDrawing); final IndexedAStarPathFinder<MyNode> pathfinder = new IndexedAStarPathFinder<>(graph); final GraphPath<MyNode> outPath = new DefaultGraphPath<>(); // @off - disable libgdx formatter // 0123456789 // S....#...E 0 // .....#.... 10 // .....#.... 20 // @on - enable libgdx formatter final boolean searchResult = pathfinder.searchNodePath(graph.nodes.get(0), graph.nodes.get(9), new ManhattanDistance(), outPath); Assert.assertFalse("Unexpected search result", searchResult); }
Example #2
Source File: MapGraph.java From riiablo with Apache License 2.0 | 5 votes |
public boolean searchNodePath(PathFinder pathFinder, Vector2 src, Vector2 dst, int flags, int size, GraphPath<Point2> outPath) { outPath.clear(); if (dst == null) return false; if (map.flags(dst) != 0) return false; Point2 srcP = getOrCreate(src); Point2 dstP = getOrCreate(dst); return searchNodePath(pathFinder, srcP, dstP, flags, size, outPath); }
Example #3
Source File: AStarPathFinder.java From riiablo with Apache License 2.0 | 5 votes |
protected void generateNodePath(Point2 startNode, GraphPath<Point2> outPath) { while (current.parent != null) { outPath.add(current); current = current.parent; } outPath.add(startNode); outPath.reverse(); }
Example #4
Source File: IndexedAStarPathFinder.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public boolean searchConnectionPath (N startNode, N endNode, Heuristic<N> heuristic, GraphPath<Connection<N>> outPath) { // Perform AStar boolean found = search(startNode, endNode, heuristic); if (found) { // Create a path made of connections generateConnectionPath(startNode, outPath); } return found; }
Example #5
Source File: IndexedAStarPathFinder.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public boolean searchNodePath (N startNode, N endNode, Heuristic<N> heuristic, GraphPath<N> outPath) { // Perform AStar boolean found = search(startNode, endNode, heuristic); if (found) { // Create a path made of nodes generateNodePath(startNode, outPath); } return found; }
Example #6
Source File: IndexedAStarPathFinder.java From gdx-ai with Apache License 2.0 | 5 votes |
protected void generateConnectionPath (N startNode, GraphPath<Connection<N>> outPath) { // Work back along the path, accumulating connections // outPath.clear(); while (current.node != startNode) { outPath.add(current.connection); current = nodeRecords[graph.getIndex(current.connection.getFromNode())]; } // Reverse the path outPath.reverse(); }
Example #7
Source File: IndexedAStarPathFinder.java From gdx-ai with Apache License 2.0 | 5 votes |
protected void generateNodePath (N startNode, GraphPath<N> outPath) { // Work back along the path, accumulating nodes // outPath.clear(); while (current.connection != null) { outPath.add(current.node); current = nodeRecords[graph.getIndex(current.connection.getFromNode())]; } outPath.add(startNode); // Reverse the path outPath.reverse(); }
Example #8
Source File: MapGraph.java From riiablo with Apache License 2.0 | 4 votes |
boolean searchNodePath(PathFinder pathFinder, Point2 src, Point2 dst, int flags, int size, GraphPath<Point2> outPath) { return pathFinder.search(src, dst, flags, size, outPath); }
Example #9
Source File: Map.java From riiablo with Apache License 2.0 | 4 votes |
public boolean findPath(Vector2 src, Vector2 dst, GraphPath<Point2> path) { return findPath(src, dst, DT1.Tile.FLAG_BLOCK_WALK, 0, path); }
Example #10
Source File: Map.java From riiablo with Apache License 2.0 | 4 votes |
public boolean findPath(Vector2 src, Vector2 dst, int flags, int size, GraphPath<Point2> path) { return mapGraph.searchNodePath(pathFinder, src, dst, flags, size, path); }
Example #11
Source File: AStarPathFinder.java From riiablo with Apache License 2.0 | 4 votes |
public boolean search(Point2 startNode, Point2 endNode, int flags, int size, GraphPath<Point2> outPath) { boolean found = search(startNode, endNode, flags, size); if (found) generateNodePath(startNode, outPath); return found; }
Example #12
Source File: IndexedAStarPathFinderTest.java From gdx-ai with Apache License 2.0 | 4 votes |
@Test public void searchNodePath_WhenSearchingAdjacentTile_ExpectedOuputPathLengthEquals2 () { // @off - disable libgdx formatter final String graphDrawing = "..........\n" + "..........\n" + ".........."; // @on - enable libgdx formatter final MyGraph graph = createGraphFromTextRepresentation(graphDrawing); final IndexedAStarPathFinder<MyNode> pathfinder = new IndexedAStarPathFinder<>(graph); final GraphPath<MyNode> outPath = new DefaultGraphPath<>(); // @off - disable libgdx formatter // 0123456789 // .......... 0 // .....S.... 10 // .....E.... 20 // @on - enable libgdx formatter final boolean searchResult1 = pathfinder.searchNodePath(graph.nodes.get(15), graph.nodes.get(25), new ManhattanDistance(), outPath); Assert.assertTrue("Unexpected search result", searchResult1); Assert.assertEquals("Unexpected number of nodes in path", 2, outPath.getCount()); // @off - disable libgdx formatter // 0123456789 // .......... 0 // .....SE... 10 // .......... 20 // @on - enable libgdx formatter outPath.clear(); final boolean searchResult2 = pathfinder.searchNodePath(graph.nodes.get(15), graph.nodes.get(16), new ManhattanDistance(), outPath); Assert.assertTrue("Unexpected search result", searchResult2); Assert.assertEquals("Unexpected number of nodes in path", 2, outPath.getCount()); // @off - disable libgdx formatter // 0123456789 // .......... 0 // ....ES.... 10 // .......... 20 // @on - enable libgdx formatter outPath.clear(); final boolean searchResult3 = pathfinder.searchNodePath(graph.nodes.get(15), graph.nodes.get(14), new ManhattanDistance(), outPath); Assert.assertTrue("Unexpected search result", searchResult3); Assert.assertEquals("Unexpected number of nodes in path", 2, outPath.getCount()); // @off - disable libgdx formatter // 0123456789 // .....E.... 0 // .....S.... 10 // .......... 20 // @on - enable libgdx formatter outPath.clear(); final boolean searchResult4 = pathfinder.searchNodePath(graph.nodes.get(15), graph.nodes.get(5), new ManhattanDistance(), outPath); Assert.assertTrue("Unexpected search result", searchResult4); Assert.assertEquals("Unexpected number of nodes in path", 2, outPath.getCount()); }
Example #13
Source File: IndexedAStarPathFinderTest.java From gdx-ai with Apache License 2.0 | 4 votes |
@Test public void searchNodePath_WhenSearchCanHitDeadEnds_ExpectedOuputPathFound () { // @off - disable libgdx formatter final String graphDrawing = ".#.#.......#..#...............\n" + ".#............#.....#..#####..\n" + "...#.#######..#.....#.........\n" + ".#.#.#........#.....########..\n" + ".###.#....#####.....#......##.\n" + ".#...#....#.........#...##....\n" + ".#####....#.........#....#....\n" + ".#........#.........#....#####\n" + ".####....##.........#......#..\n" + "....#...............#......#.."; // @on - enable libgdx formatter final MyGraph graph = createGraphFromTextRepresentation(graphDrawing); final IndexedAStarPathFinder<MyNode> pathfinder = new IndexedAStarPathFinder<>(graph); final GraphPath<MyNode> outPath = new DefaultGraphPath<>(); // @off - disable libgdx formatter // 012345678901234567890123456789 // S#.#.......#..#............... 0 // .#............#.....#..#####.. 30 // ...#.#######..#.....#......... 60 // .#.#.#........#.....########.. 90 // .###.#....#####.....#......##. 120 // .#...#....#.........#...##.... 150 // .#####....#.........#....#.... 180 // .#E.......#.........#....##### 210 // .####....##.........#......#.. 240 // ....#...............#......#.. 270 // @on - enable libgdx formatter final boolean searchResult = pathfinder.searchNodePath(graph.nodes.get(0), graph.nodes.get(212), new ManhattanDistance(), outPath); Assert.assertTrue("Unexpected search result", searchResult); Assert.assertEquals("Unexpected number of nodes in path", 32, outPath.getCount()); }
Example #14
Source File: PathFinder.java From riiablo with Apache License 2.0 | votes |
boolean search(Point2 startNode, Point2 endNode, int flags, int size, GraphPath<Point2> outPath);