From d1444a366f4052f315fe970dfedbc8a3d9725235 Mon Sep 17 00:00:00 2001 From: romanschenk37 <84532681+romanschenk37@users.noreply.github.com> Date: Fri, 25 Mar 2022 19:16:17 +0100 Subject: [PATCH] Code Cleanup --- .../strategy/PathFinderMoveStrategy.java | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderMoveStrategy.java b/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderMoveStrategy.java index b9feee0..178775c 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderMoveStrategy.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderMoveStrategy.java @@ -10,13 +10,13 @@ import java.util.List; * Strategy which calculates the path automatically */ public class PathFinderMoveStrategy implements MoveStrategy{ - private Track track; - private int carIndex; + private final Track track; + private final int carIndex; private List moveList; // the index of the next move in moveList private int pointer; // all Directions which can be used for acceleration - private PositionVector.Direction[] allDirections; + private final PositionVector.Direction[] allDirections; // List of all States (combination of Position and Velocity) which are already reached with a calculated move. private List calculatedStates; @@ -60,7 +60,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{ for(PositionVector.Direction direction : allDirections){ PossibleMove newMove = new PossibleMove(previousMove, direction); State newState = new State(newMove.endPosition, newMove.endVelocity); - //only use the new created Possible Move if it doen't crash, end State isn't in List of calculatedStates + //only use the new created Possible Move if it doesn't crash, end State isn't in List of calculatedStates // and if there is no move found yet which is finished. if(! (newMove.crashed() || alreadyCalculated(newState) || finishedMove != null)){ if(newMove.finished()){ @@ -76,7 +76,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{ } - // if a finished Move is found save it's directions as moveList + // if a finished Move is found save its directions as moveList moveList = finishedMove.directions; } @@ -97,7 +97,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{ /** * Combination of position and velocity */ - public class State{ + public static class State{ PositionVector position; PositionVector velocity; @@ -117,11 +117,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{ * @return true if it is equal, false if it is not equal */ public boolean equals(State compareState){ - if(compareState.position.equals(position) && compareState.velocity.equals(velocity)){ - return true; - } else{ - return false; - } + return compareState.position.equals(position) && compareState.velocity.equals(velocity); } } @@ -168,12 +164,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{ * @return true if finishline will be crossed */ public boolean finished(){ - if(track.calculateNewWinPoints(startPosition, endPosition) == 1){ - return true; - } - else{ - return false; - } + return track.calculateNewWinPoints(startPosition, endPosition) == 1; } /** @@ -187,10 +178,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{ return true; } } - if(track.calculateNewWinPoints(startPosition, endPosition) == -1){ - return true; - } - return false; + return track.calculateNewWinPoints(startPosition, endPosition) == -1; } }