com.badlogic.gdx.ai.pfa.DefaultGraphPath Java Examples

The following examples show how to use com.badlogic.gdx.ai.pfa.DefaultGraphPath. 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 vote down vote up
@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: AStartPathFinding.java    From Pacman_libGdx with MIT License 5 votes vote down vote up
public AStartPathFinding(AStarMap map) {
    this.map = map;
    this.pathfinder = new IndexedAStarPathFinder<Node>(createGraph(map));
    this.connectionPath = new DefaultGraphPath<Connection<Node>>();
    this.heuristic = new Heuristic<Node>() {
        @Override
        public float estimate (Node node, Node endNode) {
            // Manhattan distance
            return Math.abs(endNode.x - node.x) + Math.abs(endNode.y - node.y);
        }
  };
}
 
Example #3
Source File: IndexedAStarPathFinderTest.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
@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 #4
Source File: IndexedAStarPathFinderTest.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
@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());
}