|
|
|
|
@ -5,22 +5,23 @@ import shared.model.Wind;
|
|
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by jjg64 on 28/08/17.
|
|
|
|
|
*/
|
|
|
|
|
public class ShiftingWindGenerator implements WindGenerator {
|
|
|
|
|
Bearing baselineBearing;
|
|
|
|
|
double baseLineSpeed;
|
|
|
|
|
double windSpeedVariance = 5;
|
|
|
|
|
double bearingVariance = 5; // In degrees
|
|
|
|
|
double oscillationVariance = 0.25;
|
|
|
|
|
double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds
|
|
|
|
|
|
|
|
|
|
double timeOfLastOscillationReset = 0;
|
|
|
|
|
double timeOfLastChange = 0;
|
|
|
|
|
double timeSinceLastShift = 0; // Back / veer
|
|
|
|
|
|
|
|
|
|
boolean anticlockwise = false;
|
|
|
|
|
private Bearing baselineBearing;
|
|
|
|
|
private double baseLineSpeed;
|
|
|
|
|
private double windSpeedVariance = 5;
|
|
|
|
|
private double bearingVariance = 5; // In degrees
|
|
|
|
|
private double oscillationVariance = 0.25;
|
|
|
|
|
private double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds
|
|
|
|
|
private double shiftTime = 1e3 * 60;
|
|
|
|
|
private double shiftedSoFar = 0;
|
|
|
|
|
|
|
|
|
|
private double timeOfLastOscillationReset = 0;
|
|
|
|
|
private double timeOfLastChange = 0;
|
|
|
|
|
private double timeOfLastShift = 0; // Back / veer
|
|
|
|
|
|
|
|
|
|
private boolean anticlockwise = false;
|
|
|
|
|
private boolean shiftAnticlockwise = false;//true for Back, false for veer
|
|
|
|
|
private boolean shiftThisRace = Math.random() > 0.5;
|
|
|
|
|
|
|
|
|
|
public ShiftingWindGenerator(Bearing baselineBearing, double baseLineSpeed) {
|
|
|
|
|
this.baselineBearing = baselineBearing;
|
|
|
|
|
@ -41,7 +42,7 @@ public class ShiftingWindGenerator implements WindGenerator {
|
|
|
|
|
private Wind changeWind(Wind wind) {
|
|
|
|
|
Wind newWind = new Wind(wind.getWindDirection(), wind.getWindSpeed());
|
|
|
|
|
oscillateWind(newWind);
|
|
|
|
|
shiftWind(newWind);
|
|
|
|
|
if (shiftThisRace){shiftWind(newWind);}
|
|
|
|
|
changeWindSpeed(newWind);
|
|
|
|
|
timeOfLastChange = System.currentTimeMillis();
|
|
|
|
|
return newWind;
|
|
|
|
|
@ -78,6 +79,27 @@ public class ShiftingWindGenerator implements WindGenerator {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void shiftWind(Wind wind) {
|
|
|
|
|
double timeSinceLastShift = System.currentTimeMillis() - timeOfLastShift;
|
|
|
|
|
double newBearing = wind.getWindDirection().degrees();
|
|
|
|
|
double degreeChange = 7;
|
|
|
|
|
|
|
|
|
|
if (timeSinceLastShift >= shiftTime){
|
|
|
|
|
shiftedSoFar += degreeChange;
|
|
|
|
|
if (shiftedSoFar >= 180){
|
|
|
|
|
shiftAnticlockwise = Math.random() > 0.5;
|
|
|
|
|
shiftedSoFar = 0;
|
|
|
|
|
System.out.println("Swapping");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timeOfLastShift = System.currentTimeMillis();
|
|
|
|
|
if (shiftAnticlockwise){
|
|
|
|
|
newBearing -= degreeChange;
|
|
|
|
|
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
|
|
|
|
|
} else {
|
|
|
|
|
newBearing += degreeChange;
|
|
|
|
|
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void changeWindSpeed(Wind wind) {
|
|
|
|
|
|