Code Cleanup
This commit is contained in:
parent
3761377b61
commit
d1444a366f
|
@ -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<PositionVector.Direction> 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<State> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue