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
public int getWinner() {
if (onlyOneCarLeft()) {
return currentCarIndex;
}
for (int i = 0; i < track.getCarCount(); i++) {
if (track.getCar(i).getWinPoints() == 1) {
return i;
}
}
if (onlyOneCarLeft()) {
return currentCarIndex;
}
return NO_WINNER;
}
@ -221,15 +221,15 @@ public class Game implements GameSpecification {
break;
}
}
if (crashPosition != null) {
track.carDoesCrash(currentCarIndex, crashPosition);
} else {
int newWinPoints = track.calculateNewWinPoints(track.getCarPos(currentCarIndex), track.getCar(currentCarIndex).nextPosition());
if(newWinPoints == 1){
track.getCar(currentCarIndex).increaseWinPoints();
}else if(newWinPoints == 1){
}else if(newWinPoints == -1){
track.getCar(currentCarIndex).deductWinPoints();
}
if (crashPosition != null) {
track.carDoesCrash(currentCarIndex, crashPosition);
} else {
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(PositionVector.Direction direction : allDirections){
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);
}
}
}
possibleMoves = newMoves;
finishedMove = findFinishedMove(possibleMoves);
}
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 {
List<PositionVector.Direction> directions;
@ -95,6 +90,9 @@ public class PathFinderMoveStrategy implements MoveStrategy{
return true;
}
}
if(track.calculateNewWinPoints(positions.get(positions.size()-2), positions.get(positions.size()-1)) == -1){
return true;
}
return false;
}