Strategy #31
			
				
			
		
		
		
	| 
						 | 
				
			
			@ -21,11 +21,10 @@ public class PathFinderMoveStrategy implements MoveStrategy{
 | 
			
		|||
        this.carIndex = carIndex;
 | 
			
		||||
        allDirections = Arrays.asList(PositionVector.Direction.values());
 | 
			
		||||
        createMoveList();
 | 
			
		||||
        pointer = -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private void createMoveList(){
 | 
			
		||||
        pointer = -1;
 | 
			
		||||
        calculatedStates = new ArrayList<>();
 | 
			
		||||
        PossibleMove finishedMove = null;
 | 
			
		||||
        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
 | 
			
		||||
        pointer += 1;
 | 
			
		||||
        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 null;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue