From b541f72e8457a7a184188706f4713826596d3ba2 Mon Sep 17 00:00:00 2001 From: GodCipher Date: Wed, 4 Sep 2024 00:35:56 +0200 Subject: [PATCH] refact: maxIterationsReached-check was taken from backupPathfindingOrFailure and placed infront. --- .../pathfinder/AbstractPathfinder.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/pathetic-model/src/main/java/org/patheloper/model/pathing/pathfinder/AbstractPathfinder.java b/pathetic-model/src/main/java/org/patheloper/model/pathing/pathfinder/AbstractPathfinder.java index 0c3d77af..3e60a12b 100644 --- a/pathetic-model/src/main/java/org/patheloper/model/pathing/pathfinder/AbstractPathfinder.java +++ b/pathetic-model/src/main/java/org/patheloper/model/pathing/pathfinder/AbstractPathfinder.java @@ -190,7 +190,13 @@ private PathfinderResult executePathing( tick(start, target, currentNode, depth, nodeQueue, examinedPositions, filters); } - return backupPathfindingOrFailure(depth, start, target, filters, fallbackNode); + + Optional maxIterationsResult = maxIterationsReached(depth, fallbackNode); + if (maxIterationsResult.isPresent()) { + return maxIterationsResult.get(); + } + + return backupPathfindingOrFailure(start, target, filters, fallbackNode); } catch (Exception e) { throw ErrorLogger.logFatalErrorWithStacktrace("Failed to find path", e); } @@ -259,16 +265,7 @@ private PathfinderResult resetAbortedAndFinishPathing(PathState pathState, Node /** 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 filters, - Node fallbackNode) { - - Optional maxIterationsResult = maxIterationsReached(depth, fallbackNode); - if (maxIterationsResult.isPresent()) { - return maxIterationsResult.get(); - } + PathPosition start, PathPosition target, List filters, Node fallbackNode) { Optional counterCheckResult = counterCheck(start, target, filters); if (counterCheckResult.isPresent()) {