Skip to content

Commit

Permalink
feat: remove deprecated counterCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Metaphoriker committed Sep 23, 2024
1 parent 87d5980 commit cbf8d61
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ public class PathfinderConfiguration {
*/
boolean loadingChunks;

/**
* If pathfinding fails, determines whether to run a reverse pathfinding check (from target to
* start) to verify the result. This is a computationally expensive fallback but can help identify
* some failure cases.
*
* @deprecated This feature is deprecated and may be removed in a future release.
*/
@Deprecated
boolean counterCheck;

/**
* Determines whether the pathfinding algorithm should see PathFilterStages as prioritization,
* instead of filtering. This means that the pathfinding algorithm will prioritize paths that pass
Expand Down Expand Up @@ -138,7 +128,6 @@ public static PathfinderConfiguration deepCopy(PathfinderConfiguration pathfinde
.allowingFailFast(pathfinderConfiguration.allowingFailFast)
.allowingFallback(pathfinderConfiguration.allowingFallback)
.loadingChunks(pathfinderConfiguration.loadingChunks)
.counterCheck(pathfinderConfiguration.counterCheck)
.heuristicWeights(pathfinderConfiguration.heuristicWeights)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -204,7 +203,7 @@ private PathfinderResult executePathing(

aborted = false; // just in case

return backupPathfindingOrFailure(depth, start, target, filters, fallbackNode);
return backupPathfindingOrFailure(depth, start, target, fallbackNode);
} catch (Exception e) {
throw ErrorLogger.logFatalErrorWithStacktrace("Failed to find path", e);
}
Expand Down Expand Up @@ -291,22 +290,13 @@ private PathfinderResult finishPathing(PathState pathState, Node currentNode) {

/** If the pathfinder has failed to find a path, it will try to still give a result. */
private PathfinderResult backupPathfindingOrFailure(
Depth depth,
PathPosition start,
PathPosition target,
List<PathFilter> filters,
Node fallbackNode) {
Depth depth, PathPosition start, PathPosition target, Node fallbackNode) {

Optional<PathfinderResult> maxIterationsResult = maxIterationsReached(depth, fallbackNode);
if (maxIterationsResult.isPresent()) {
return maxIterationsResult.get();
}

Optional<PathfinderResult> counterCheckResult = counterCheck(start, target, filters);
if (counterCheckResult.isPresent()) {
return counterCheckResult.get();
}

Optional<PathfinderResult> fallbackResult = fallback(fallbackNode);
return fallbackResult.orElseGet(
() ->
Expand All @@ -332,29 +322,6 @@ private Optional<PathfinderResult> fallback(Node fallbackNode) {
return Optional.empty();
}

private Optional<PathfinderResult> counterCheck(
PathPosition start, PathPosition target, List<PathFilter> filters) {
if (!pathfinderConfiguration.isCounterCheck()) {
return Optional.empty();
}

AStarPathfinder aStarPathfinder =
new AStarPathfinder(
PathfinderConfiguration.deepCopy(pathfinderConfiguration).withCounterCheck(false));
try {
PathfinderResult pathfinderResult =
aStarPathfinder.findPath(start, target, filters).toCompletableFuture().get();

if (pathfinderResult.getPathState() == PathState.FOUND) {
return Optional.of(pathfinderResult);
}
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}

return Optional.empty();
}

private Path fetchRetracedPath(@NonNull Node node) {
if (node.getParent() == null)
return new PathImpl(
Expand Down

0 comments on commit cbf8d61

Please sign in to comment.