Started implementing wind oscillation. #story[1187]
This commit is contained in:
@@ -5,6 +5,7 @@ import mock.exceptions.EventConstructionException;
|
|||||||
import mock.model.*;
|
import mock.model.*;
|
||||||
import mock.model.commandFactory.CompositeCommand;
|
import mock.model.commandFactory.CompositeCommand;
|
||||||
import mock.model.wind.RandomWindGenerator;
|
import mock.model.wind.RandomWindGenerator;
|
||||||
|
import mock.model.wind.ShiftingWindGenerator;
|
||||||
import mock.model.wind.WindGenerator;
|
import mock.model.wind.WindGenerator;
|
||||||
import mock.xml.RaceXMLCreator;
|
import mock.xml.RaceXMLCreator;
|
||||||
import network.Messages.LatestMessages;
|
import network.Messages.LatestMessages;
|
||||||
@@ -124,13 +125,17 @@ public class Event {
|
|||||||
this.latestMessages = new LatestMessages();
|
this.latestMessages = new LatestMessages();
|
||||||
|
|
||||||
//Create and start race.
|
//Create and start race.
|
||||||
WindGenerator windGenerator = new RandomWindGenerator(
|
// WindGenerator windGenerator = new RandomWindGenerator(
|
||||||
|
// Bearing.fromDegrees(225),
|
||||||
|
// Bearing.fromDegrees(215),
|
||||||
|
// Bearing.fromDegrees(235),
|
||||||
|
// 12d,
|
||||||
|
// 8d,
|
||||||
|
// 16d );
|
||||||
|
WindGenerator windGenerator = new ShiftingWindGenerator(
|
||||||
Bearing.fromDegrees(225),
|
Bearing.fromDegrees(225),
|
||||||
Bearing.fromDegrees(215),
|
12
|
||||||
Bearing.fromDegrees(235),
|
);
|
||||||
12d,
|
|
||||||
8d,
|
|
||||||
16d );
|
|
||||||
RaceLogic newRace = new RaceLogic(
|
RaceLogic newRace = new RaceLogic(
|
||||||
new MockRace(
|
new MockRace(
|
||||||
boatDataSource,
|
boatDataSource,
|
||||||
|
|||||||
@@ -3,18 +3,28 @@ package mock.model.wind;
|
|||||||
import shared.model.Bearing;
|
import shared.model.Bearing;
|
||||||
import shared.model.Wind;
|
import shared.model.Wind;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by jjg64 on 28/08/17.
|
* Created by jjg64 on 28/08/17.
|
||||||
*/
|
*/
|
||||||
public class ShiftingWindGenerator implements WindGenerator {
|
public class ShiftingWindGenerator implements WindGenerator {
|
||||||
Bearing baselineBearing;
|
Bearing baselineBearing;
|
||||||
double baseLineSpeed;
|
double baseLineSpeed;
|
||||||
double maxBearingVariance = 5; // In degrees
|
double speedVariance = 4;
|
||||||
|
double bearingVariance = 5; // In degrees
|
||||||
double oscillationPeriod = 3e6; // In milliseconds
|
double oscillationPeriod = 3e6; // In milliseconds
|
||||||
|
|
||||||
|
double timeOfLastOscillationReset = 0;
|
||||||
|
double timeSinceLastChange = 0;
|
||||||
|
double timeSinceLastShift = 0; // Back / veer
|
||||||
|
|
||||||
|
boolean oscillationLeft = false;
|
||||||
|
|
||||||
public ShiftingWindGenerator(Bearing baselineBearing, double baseLineSpeed) {
|
public ShiftingWindGenerator(Bearing baselineBearing, double baseLineSpeed) {
|
||||||
this.baselineBearing = baselineBearing;
|
this.baselineBearing = baselineBearing;
|
||||||
this.baseLineSpeed = baseLineSpeed;
|
this.baseLineSpeed = baseLineSpeed;
|
||||||
|
initialiseOscillationDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -27,22 +37,39 @@ public class ShiftingWindGenerator implements WindGenerator {
|
|||||||
return changeWind(currentWind);
|
return changeWind(currentWind);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Wind changeWind(Wind currentWind) {
|
private Wind changeWind(Wind wind) {
|
||||||
currentWind = oscillateWind(currentWind);
|
Wind newWind = new Wind(wind.getWindDirection(), wind.getWindSpeed());
|
||||||
currentWind = shiftWind(currentWind);
|
oscillateWind(newWind);
|
||||||
return currentWind;
|
shiftWind(newWind);
|
||||||
|
changeWindSpeed(newWind);
|
||||||
|
return newWind;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Wind oscillateWind(Wind currentWind) {
|
private void oscillateWind(Wind wind) {
|
||||||
return currentWind;
|
double timeSinceLastOscillationReset = System.currentTimeMillis() - timeOfLastOscillationReset;
|
||||||
|
if (oscillationLeft) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Wind shiftWind(Wind currentWind) {
|
private void shiftWind(Wind wind) {
|
||||||
return currentWind;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxBearingVariance(double maxBearingVariance) {
|
private void changeWindSpeed(Wind wind) {
|
||||||
this.maxBearingVariance = maxBearingVariance;
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialiseOscillationDirection() {
|
||||||
|
oscillationLeft = new Random().nextBoolean();
|
||||||
|
timeOfLastOscillationReset = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBearingVariance(double maxBearingVariance) {
|
||||||
|
this.bearingVariance = maxBearingVariance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpeedVariance(double speedVariance) {
|
||||||
|
this.speedVariance = speedVariance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOscillationPeriod(double oscillationPeriod) {
|
public void setOscillationPeriod(double oscillationPeriod) {
|
||||||
|
|||||||
@@ -48,4 +48,11 @@ public class Wind {
|
|||||||
return windSpeed;
|
return windSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWindSpeed(double windSpeed) {
|
||||||
|
this.windSpeed = windSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWindDirection(Bearing windDirection) {
|
||||||
|
this.windDirection = windDirection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user