Strategy #31
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (crashPosition != null) {
|
|
||||||
track.carDoesCrash(currentCarIndex, crashPosition);
|
|
||||||
} else {
|
|
||||||
int newWinPoints = track.calculateNewWinPoints(track.getCarPos(currentCarIndex), track.getCar(currentCarIndex).nextPosition());
|
int newWinPoints = track.calculateNewWinPoints(track.getCarPos(currentCarIndex), track.getCar(currentCarIndex).nextPosition());
|
||||||
if(newWinPoints == 1){
|
if(newWinPoints == 1){
|
||||||
track.getCar(currentCarIndex).increaseWinPoints();
|
track.getCar(currentCarIndex).increaseWinPoints();
|
||||||
}else if(newWinPoints == 1){
|
}else if(newWinPoints == -1){
|
||||||
track.getCar(currentCarIndex).deductWinPoints();
|
track.getCar(currentCarIndex).deductWinPoints();
|
||||||
}
|
}
|
||||||
|
if (crashPosition != null) {
|
||||||
|
track.carDoesCrash(currentCarIndex, crashPosition);
|
||||||
|
} else {
|
||||||
track.moveCar(currentCarIndex);
|
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(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue