Strategy #31

Merged
schrom01 merged 24 commits from Strategy into main 2022-03-25 09:24:21 +01:00
4 changed files with 21 additions and 23 deletions
Showing only changes of commit e84bce43af - Show all commits

View File

@ -169,14 +169,14 @@ public class Game implements GameSpecification {
*/ */
@Override @Override
public int getWinner() { public int getWinner() {
if (onlyOneCarLeft()) {
return currentCarIndex;
}
for (int i = 0; i < track.getCarCount(); i++) { for (int i = 0; i < track.getCarCount(); i++) {
if (track.getCar(i).getWinPoints() == 1) { if (track.getCar(i).getWinPoints() == 1) {
return i; return i;
} }
} }
if (onlyOneCarLeft()) {
return currentCarIndex;
}
return NO_WINNER; return NO_WINNER;
} }
@ -221,15 +221,15 @@ public class Game implements GameSpecification {
break; break;
} }
} }
int newWinPoints = track.calculateNewWinPoints(track.getCarPos(currentCarIndex), track.getCar(currentCarIndex).nextPosition());
if(newWinPoints == 1){
track.getCar(currentCarIndex).increaseWinPoints();
}else if(newWinPoints == -1){
track.getCar(currentCarIndex).deductWinPoints();
}
if (crashPosition != null) { if (crashPosition != null) {
track.carDoesCrash(currentCarIndex, crashPosition); track.carDoesCrash(currentCarIndex, crashPosition);
} else { } else {
int newWinPoints = track.calculateNewWinPoints(track.getCarPos(currentCarIndex), track.getCar(currentCarIndex).nextPosition());
if(newWinPoints == 1){
track.getCar(currentCarIndex).increaseWinPoints();
}else if(newWinPoints == 1){
track.getCar(currentCarIndex).deductWinPoints();
}
track.moveCar(currentCarIndex); track.moveCar(currentCarIndex);
} }
} }

View File

@ -284,7 +284,7 @@ public class Track implements TrackSpecification {
} }
} }
return null; return ConfigSpecification.SpaceType.WALL;
} }
/** /**

View File

@ -33,13 +33,17 @@ public class PathFinderMoveStrategy implements MoveStrategy{
for(PossibleMove previousMove : possibleMoves){ for(PossibleMove previousMove : possibleMoves){
for(PositionVector.Direction direction : allDirections){ for(PositionVector.Direction direction : allDirections){
PossibleMove newMove = new PossibleMove(previousMove, direction); PossibleMove newMove = new PossibleMove(previousMove, direction);
if(! (newMove.crashed() || newMove.drivingLoop())){ if(! (newMove.crashed() || newMove.drivingLoop() || finishedMove != null)){
if(newMove.finished()){
finishedMove = newMove;
break;
}
newMoves.add(newMove); newMoves.add(newMove);
} }
} }
} }
possibleMoves = newMoves; possibleMoves = newMoves;
finishedMove = findFinishedMove(possibleMoves);
} }
moveList = finishedMove.directions; moveList = finishedMove.directions;
@ -47,15 +51,6 @@ public class PathFinderMoveStrategy implements MoveStrategy{
} }
private PossibleMove findFinishedMove(List<PossibleMove> moveList){
for(PossibleMove move : moveList){
if(move.finished()){
return move;
}
}
return null;
}
public class PossibleMove { public class PossibleMove {
List<PositionVector.Direction> directions; List<PositionVector.Direction> directions;
@ -91,10 +86,13 @@ public class PathFinderMoveStrategy implements MoveStrategy{
public boolean crashed() { public boolean crashed() {
for(PositionVector point : track.calculatePointsOnPath(positions.get(positions.size()-2), positions.get(positions.size()-1))) { for(PositionVector point : track.calculatePointsOnPath(positions.get(positions.size()-2), positions.get(positions.size()-1))) {
if (track.willCrashAtPosition(carIndex, point)) { if (track.willCrashAtPosition(carIndex, point)){
return true; return true;
} }
} }
if(track.calculateNewWinPoints(positions.get(positions.size()-2), positions.get(positions.size()-1)) == -1){
return true;
}
return false; return false;
} }

View File

@ -1,7 +1,7 @@
############################################################ ############################################################
############################################################ ############################################################
####### < ## ####### < ##
####### < § ## ####### < § ##
####### < ## ####### < ##
####### < @ ## ####### < @ ##
####### < ## ####### < ##