Finds the fastest path between a starting and ending location using A , then removes unneeded steps for straight @param start The starting block @param end The ending block @param max The max number of locations to be checked - use to limit runtime @param filter A filter to determine which b
(Block start, Block end, int max, Predicate<Block> filter)
| 375 | * be completed |
| 376 | */ |
| 377 | public static List<Location> directPathfind(Block start, Block end, int max, Predicate<Block> filter) { |
| 378 | List<Location> path = new ArrayList<>(pathfind(start, end, max, filter)); |
| 379 | for (int i = 0; i + 2 < path.size(); i += 2) { |
| 380 | Location first = path.get(i); |
| 381 | Location second = path.get(i + 2); |
| 382 | if (Path.getPath(first, second, 0.25).stream().map(Location::getBlock).allMatch(filter)) { |
| 383 | path.remove(i + 1); |
| 384 | i -= 2; |
| 385 | } |
| 386 | } |
| 387 | return path; |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Finds the fastest path between a starting and ending location using A*, then removes unneeded steps for straight |