@Test public void testFindPath() { Map<String, String> properties = new HashMap<>(); properties.put("walkable", "false"); Location[] obstacles = { new Location(0, 8, properties), new Location(1, 8, properties), new Location(2, 8, properties), new Location(3, 8, properties), new Location(4, 8, properties), new Location(5, 8, properties), new Location(6, 8, properties), new Location(7, 8, properties), new Location(8, 8, properties), new Location(8, 7, properties), new Location(8, 6, properties), new Location(8, 5, properties), new Location(8, 4, properties), new Location(8, 3, properties), new Location(9, 3, properties)}; LinkedList<Location> expectedPath = new LinkedList<>(Arrays.asList( new Location(5, 5), new Location(5, 4), new Location(6, 3), new Location(7, 2), new Location(8, 2), new Location(9, 2), new Location(10, 2), new Location(10, 3), new Location(10, 4), new Location(9, 5), new Location(9, 6), new Location(9, 7), new Location(9, 8), new Location(9, 9), new Location(8, 10), new Location(7, 11), new Location(6, 12), new Location(5, 13), new Location(5, 14), new Location(5, 15))); Zone zone = new Zone(0, new Dimension2D(20, 20), obstacles); Location start = ZoneUtils.getLocationOnGrid(zone, 5, 5); Location end = ZoneUtils.getLocationOnGrid(zone, 5, 15); Pathfinder pathfinder = new Pathfinder(zone, start, end); LinkedList<Location> actualPath = pathfinder.findPath(); Assert.assertEquals(actualPath, expectedPath); }
public LinkedList<Location> findPath() { LinkedList<PathNode> openList = new LinkedList<>(); LinkedList<PathNode> closedList = new LinkedList<>(); PathNode selectedPathNode = new PathNode(start, end); openList.add(selectedPathNode); while (selectedPathNode.location != end && !openList.isEmpty() && openList.size() < NODE_LIMIT) { selectedPathNode = getLowestFNode(openList); moveNodeFromOpenToClosed(openList, closedList, selectedPathNode); addAdjacentToCorrectList(openList, closedList, selectedPathNode); } LinkedList<Location> path = new LinkedList<>(); if (selectedPathNode.location == end) { path = getReverseNodeTrace(selectedPathNode); } return path; }
Pathfinder { public LinkedList<Location> findPath() { LinkedList<PathNode> openList = new LinkedList<>(); LinkedList<PathNode> closedList = new LinkedList<>(); PathNode selectedPathNode = new PathNode(start, end); openList.add(selectedPathNode); while (selectedPathNode.location != end && !openList.isEmpty() && openList.size() < NODE_LIMIT) { selectedPathNode = getLowestFNode(openList); moveNodeFromOpenToClosed(openList, closedList, selectedPathNode); addAdjacentToCorrectList(openList, closedList, selectedPathNode); } LinkedList<Location> path = new LinkedList<>(); if (selectedPathNode.location == end) { path = getReverseNodeTrace(selectedPathNode); } return path; } }
Pathfinder { public LinkedList<Location> findPath() { LinkedList<PathNode> openList = new LinkedList<>(); LinkedList<PathNode> closedList = new LinkedList<>(); PathNode selectedPathNode = new PathNode(start, end); openList.add(selectedPathNode); while (selectedPathNode.location != end && !openList.isEmpty() && openList.size() < NODE_LIMIT) { selectedPathNode = getLowestFNode(openList); moveNodeFromOpenToClosed(openList, closedList, selectedPathNode); addAdjacentToCorrectList(openList, closedList, selectedPathNode); } LinkedList<Location> path = new LinkedList<>(); if (selectedPathNode.location == end) { path = getReverseNodeTrace(selectedPathNode); } return path; } Pathfinder(Zone zone, Location start, Location end); }
Pathfinder { public LinkedList<Location> findPath() { LinkedList<PathNode> openList = new LinkedList<>(); LinkedList<PathNode> closedList = new LinkedList<>(); PathNode selectedPathNode = new PathNode(start, end); openList.add(selectedPathNode); while (selectedPathNode.location != end && !openList.isEmpty() && openList.size() < NODE_LIMIT) { selectedPathNode = getLowestFNode(openList); moveNodeFromOpenToClosed(openList, closedList, selectedPathNode); addAdjacentToCorrectList(openList, closedList, selectedPathNode); } LinkedList<Location> path = new LinkedList<>(); if (selectedPathNode.location == end) { path = getReverseNodeTrace(selectedPathNode); } return path; } Pathfinder(Zone zone, Location start, Location end); LinkedList<Location> findPath(); }
Pathfinder { public LinkedList<Location> findPath() { LinkedList<PathNode> openList = new LinkedList<>(); LinkedList<PathNode> closedList = new LinkedList<>(); PathNode selectedPathNode = new PathNode(start, end); openList.add(selectedPathNode); while (selectedPathNode.location != end && !openList.isEmpty() && openList.size() < NODE_LIMIT) { selectedPathNode = getLowestFNode(openList); moveNodeFromOpenToClosed(openList, closedList, selectedPathNode); addAdjacentToCorrectList(openList, closedList, selectedPathNode); } LinkedList<Location> path = new LinkedList<>(); if (selectedPathNode.location == end) { path = getReverseNodeTrace(selectedPathNode); } return path; } Pathfinder(Zone zone, Location start, Location end); LinkedList<Location> findPath();  }