src/train/Driver.java
private double targetSpeedFromTrack() {
		boolean hasObstruction = false;
		Route r = train.getFrontCurrentRoute();
		double distanceToEnd = r.getLength() - train.getPosition();
		
		// while distance is less than the visible sight of the driver
		// FIXME: Change the fixed 500 limit
		while ( distanceToEnd < 500) {
			Point connection = r.getEnd().getConnectsTo();
			
			if ( connection == null ) {
				hasObstruction = true;
				break;
			}
			
			r = connection.getParentTrack().getRoute( connection );
			if ( r == null ) {
				hasObstruction = true;
				break;
			}
			
			distanceToEnd = distanceToEnd + r.getLength();
		}
		
		if ( hasObstruction && Speed.distanceToAchieveSpeed( train.getSpeed(), 0, trainAcceleration ) > distanceToEnd - 5)  {
			return 0;
		}
		
		return -1;
	}
//Check for obstructions along the route, stop before them
Check for obstructions along the route, stop before them
Check for obstructions along the route stop before them
private double targetSpeedFromTrack() {
		boolean hasObstruction = false;
		Route r = train.getFrontCurrentRoute();
		double distanceToEnd = r.getLength() - train.getPosition();
		while ( distanceToEnd < 500) {
			Point connection = r.getEnd().getConnectsTo();
			if ( connection == null ) {
				hasObstruction = true;
				break;
			}
			r = connection.getParentTrack().getRoute( connection );
			if ( r == null ) {
				hasObstruction = true;
				break;
			}
			distanceToEnd = distanceToEnd + r.getLength();
		}
		if ( hasObstruction && Speed.distanceToAchieveSpeed( train.getSpeed(), 0, trainAcceleration ) > distanceToEnd - 5)  {
			return 0;
		}
		return -1;
	}
private double targetSpeedFromTrack ( ) { boolean hasObstruction = false ; Route r = train . getFrontCurrentRoute ( ) ; double distanceToEnd = r . getLength ( ) - train . getPosition ( ) ; while ( distanceToEnd < 500 ) { Point connection = r . getEnd ( ) . getConnectsTo ( ) ; if ( connection == null ) { hasObstruction = true ; break ; } r = connection . getParentTrack ( ) . getRoute ( connection ) ; if ( r == null ) { hasObstruction = true ; break ; } distanceToEnd = distanceToEnd + r . getLength ( ) ; } if ( hasObstruction && Speed . distanceToAchieveSpeed ( train . getSpeed ( ) , 0 , trainAcceleration ) > distanceToEnd - 5 ) { return 0 ; } return - 1 ; }
Check for obstructions along the route, stop before them
Check for obstructions along the route stop before them
// while distance is less than the visible sight of the driver // FIXME: Change the fixed 500 limit