fix in Method calculateNewWinPoints
This commit is contained in:
parent
82911fcfb6
commit
d777b87549
|
@ -224,10 +224,10 @@ public class Game implements GameSpecification {
|
||||||
if (crashPosition != null) {
|
if (crashPosition != null) {
|
||||||
track.carDoesCrash(currentCarIndex, crashPosition);
|
track.carDoesCrash(currentCarIndex, crashPosition);
|
||||||
} else {
|
} else {
|
||||||
int newWinPoints = 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{
|
}else if(newWinPoints == 1){
|
||||||
track.getCar(currentCarIndex).deductWinPoints();
|
track.getCar(currentCarIndex).deductWinPoints();
|
||||||
}
|
}
|
||||||
track.moveCar(currentCarIndex);
|
track.moveCar(currentCarIndex);
|
||||||
|
@ -293,55 +293,6 @@ public class Game implements GameSpecification {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method will check if a car is passing the finishline.
|
|
||||||
* If the car is passing the finishline in the wrong direction, the car will lose a winpoint.
|
|
||||||
* If the car is passing the finishline in the correct direction, the car will gain a winpoint.
|
|
||||||
* @param start the startposition of the car
|
|
||||||
* @param finish the expected finishpositon of the car after the move
|
|
||||||
* @param carIndex of the current player.
|
|
||||||
*/
|
|
||||||
private int calculateNewWinPoints(PositionVector start, PositionVector finish) {
|
|
||||||
List<PositionVector> path = calculatePath(start, finish);
|
|
||||||
for (PositionVector point : path) {
|
|
||||||
if (track.getSpaceType(point) != null) {
|
|
||||||
switch (track.getSpaceType(point)) {
|
|
||||||
case FINISH_UP:
|
|
||||||
if (start.getY() < finish.getY()) {
|
|
||||||
return 1;
|
|
||||||
} else if (start.getY() > finish.getY()) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case FINISH_DOWN:
|
|
||||||
if (start.getY() > finish.getY()) {
|
|
||||||
return 1;
|
|
||||||
} else if (start.getY() < finish.getY()) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case FINISH_RIGHT:
|
|
||||||
if (start.getX() < finish.getX()) {
|
|
||||||
return 1;
|
|
||||||
} else if (start.getX() > finish.getX()) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case FINISH_LEFT:
|
|
||||||
if (start.getX() > finish.getX()) {
|
|
||||||
return 1;
|
|
||||||
} else if (start.getX() < finish.getX()) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -423,10 +423,17 @@ public class Track implements TrackSpecification {
|
||||||
return pathList;
|
return pathList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will check if a car is passing the finishline.
|
||||||
|
* If the car is passing the finishline in the wrong direction, the car will lose a winpoint.
|
||||||
|
* If the car is passing the finishline in the correct direction, the car will gain a winpoint.
|
||||||
|
* @param start the startposition of the car
|
||||||
|
* @param finish the expected finishpositon of the car after the move
|
||||||
|
* @return Number of new Winpoints for the current player.
|
||||||
|
*/
|
||||||
public int calculateNewWinPoints(PositionVector start, PositionVector finish) {
|
public int calculateNewWinPoints(PositionVector start, PositionVector finish) {
|
||||||
List<PositionVector> path = calculatePointsOnPath(start, finish);
|
List<PositionVector> path = calculatePointsOnPath(start, finish);
|
||||||
for (PositionVector point : path) {
|
for (PositionVector point : path) {
|
||||||
if (getSpaceType(point) != null) {
|
|
||||||
switch (getSpaceType(point)) {
|
switch (getSpaceType(point)) {
|
||||||
case FINISH_UP:
|
case FINISH_UP:
|
||||||
if (start.getY() < finish.getY()) {
|
if (start.getY() < finish.getY()) {
|
||||||
|
@ -456,11 +463,9 @@ public class Track implements TrackSpecification {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{
|
||||||
this.carIndex = carIndex;
|
this.carIndex = carIndex;
|
||||||
allDirections = Arrays.asList(PositionVector.Direction.values());
|
allDirections = Arrays.asList(PositionVector.Direction.values());
|
||||||
createMoveList();
|
createMoveList();
|
||||||
|
pointer = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +33,6 @@ 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())){
|
||||||
newMoves.add(newMove);
|
newMoves.add(newMove);
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,6 @@ public class PathFinderMoveStrategy implements MoveStrategy{
|
||||||
|
|
||||||
moveList = finishedMove.directions;
|
moveList = finishedMove.directions;
|
||||||
|
|
||||||
pointer = moveList.size();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +90,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean crashed() {
|
public boolean crashed() {
|
||||||
for(PositionVector point : track.calculatePointsOnPath(positions.get(positions.size()-1), positions.get(positions.size()-2))) {
|
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;
|
||||||
}
|
}
|
||||||
|
@ -115,9 +113,8 @@ public class PathFinderMoveStrategy implements MoveStrategy{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PositionVector.Direction nextMove() {
|
public PositionVector.Direction nextMove() {
|
||||||
pointer -= 1;
|
pointer += 1;
|
||||||
//TODO: Check if crash. if yes --> createMoveList();
|
if (pointer < moveList.size()) {
|
||||||
if (pointer >= 0) {
|
|
||||||
return moveList.get(pointer);
|
return moveList.get(pointer);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue