Code Cleanup

This commit is contained in:
romanschenk37 2022-03-25 19:16:17 +01:00
parent 3761377b61
commit d1444a366f
1 changed files with 9 additions and 21 deletions

View File

@ -10,13 +10,13 @@ import java.util.List;
* Strategy which calculates the path automatically * Strategy which calculates the path automatically
*/ */
public class PathFinderMoveStrategy implements MoveStrategy{ public class PathFinderMoveStrategy implements MoveStrategy{
private Track track; private final Track track;
private int carIndex; private final int carIndex;
private List<PositionVector.Direction> moveList; private List<PositionVector.Direction> moveList;
// the index of the next move in moveList // the index of the next move in moveList
private int pointer; private int pointer;
// all Directions which can be used for acceleration // 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. // List of all States (combination of Position and Velocity) which are already reached with a calculated move.
private List<State> calculatedStates; private List<State> calculatedStates;
@ -60,7 +60,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{
for(PositionVector.Direction direction : allDirections){ for(PositionVector.Direction direction : allDirections){
PossibleMove newMove = new PossibleMove(previousMove, direction); PossibleMove newMove = new PossibleMove(previousMove, direction);
State newState = new State(newMove.endPosition, newMove.endVelocity); 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. // and if there is no move found yet which is finished.
if(! (newMove.crashed() || alreadyCalculated(newState) || finishedMove != null)){ if(! (newMove.crashed() || alreadyCalculated(newState) || finishedMove != null)){
if(newMove.finished()){ 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; moveList = finishedMove.directions;
} }
@ -97,7 +97,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{
/** /**
* Combination of position and velocity * Combination of position and velocity
*/ */
public class State{ public static class State{
PositionVector position; PositionVector position;
PositionVector velocity; PositionVector velocity;
@ -117,11 +117,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{
* @return true if it is equal, false if it is not equal * @return true if it is equal, false if it is not equal
*/ */
public boolean equals(State compareState){ public boolean equals(State compareState){
if(compareState.position.equals(position) && compareState.velocity.equals(velocity)){ return compareState.position.equals(position) && compareState.velocity.equals(velocity);
return true;
} else{
return false;
}
} }
} }
@ -168,12 +164,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{
* @return true if finishline will be crossed * @return true if finishline will be crossed
*/ */
public boolean finished(){ public boolean finished(){
if(track.calculateNewWinPoints(startPosition, endPosition) == 1){ return track.calculateNewWinPoints(startPosition, endPosition) == 1;
return true;
}
else{
return false;
}
} }
/** /**
@ -187,10 +178,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{
return true; return true;
} }
} }
if(track.calculateNewWinPoints(startPosition, endPosition) == -1){ return track.calculateNewWinPoints(startPosition, endPosition) == -1;
return true;
}
return false;
} }
} }