Strategy #31
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,7 +284,7 @@ public class Track implements TrackSpecification {
|
|||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return ConfigSpecification.SpaceType.WALL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue