fixed PathFinderMoveStrategy
This commit is contained in:
parent
448e34e869
commit
d6a9b5f1aa
|
@ -21,11 +21,10 @@ 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createMoveList(){
|
private void createMoveList(){
|
||||||
|
pointer = -1;
|
||||||
calculatedStates = new ArrayList<>();
|
calculatedStates = new ArrayList<>();
|
||||||
PossibleMove finishedMove = null;
|
PossibleMove finishedMove = null;
|
||||||
List<PossibleMove> possibleMoves= new ArrayList<>();
|
List<PossibleMove> possibleMoves= new ArrayList<>();
|
||||||
|
@ -145,6 +144,22 @@ public class PathFinderMoveStrategy implements MoveStrategy{
|
||||||
public PositionVector.Direction nextMove() { //TODO check for crash and recreate movelist if crash
|
public PositionVector.Direction nextMove() { //TODO check for crash and recreate movelist if crash
|
||||||
pointer += 1;
|
pointer += 1;
|
||||||
if (pointer < moveList.size()) {
|
if (pointer < moveList.size()) {
|
||||||
|
PositionVector.Direction direction = moveList.get(pointer);
|
||||||
|
PositionVector currentVelocity = track.getCarVelocity(carIndex);
|
||||||
|
PositionVector newVelocity = new PositionVector(currentVelocity.getX() + direction.vector.getX(), currentVelocity.getY() + direction.vector.getY());
|
||||||
|
PositionVector currentPosition = track.getCarPos(carIndex);
|
||||||
|
PositionVector newPosition = new PositionVector(currentPosition.getX() + newVelocity.getX(), currentPosition.getY() + newVelocity.getY());
|
||||||
|
System.out.println("currentVelocity:" + currentVelocity.getX()+ ","+ currentVelocity.getY());
|
||||||
|
System.out.println("newVelocity:" + newVelocity.getX()+ ","+ newVelocity.getY());
|
||||||
|
for(PositionVector point : track.calculatePointsOnPath(currentPosition, newPosition)){
|
||||||
|
if(track.willCrashAtPosition(carIndex, point)){
|
||||||
|
createMoveList();
|
||||||
|
pointer = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return moveList.get(pointer);
|
return moveList.get(pointer);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue