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.commandFactory.CompositeCommand;
|
||||
import mock.model.wind.RandomWindGenerator;
|
||||
import mock.model.wind.ShiftingWindGenerator;
|
||||
import mock.model.wind.WindGenerator;
|
||||
import mock.xml.RaceXMLCreator;
|
||||
import network.Messages.LatestMessages;
|
||||
@@ -124,13 +125,17 @@ public class Event {
|
||||
this.latestMessages = new LatestMessages();
|
||||
|
||||
//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(215),
|
||||
Bearing.fromDegrees(235),
|
||||
12d,
|
||||
8d,
|
||||
16d );
|
||||
12
|
||||
);
|
||||
RaceLogic newRace = new RaceLogic(
|
||||
new MockRace(
|
||||
boatDataSource,
|
||||
|
||||
@@ -3,18 +3,28 @@ package mock.model.wind;
|
||||
import shared.model.Bearing;
|
||||
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 maxBearingVariance = 5; // In degrees
|
||||
double speedVariance = 4;
|
||||
double bearingVariance = 5; // In degrees
|
||||
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) {
|
||||
this.baselineBearing = baselineBearing;
|
||||
this.baseLineSpeed = baseLineSpeed;
|
||||
initialiseOscillationDirection();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,22 +37,39 @@ public class ShiftingWindGenerator implements WindGenerator {
|
||||
return changeWind(currentWind);
|
||||
}
|
||||
|
||||
private Wind changeWind(Wind currentWind) {
|
||||
currentWind = oscillateWind(currentWind);
|
||||
currentWind = shiftWind(currentWind);
|
||||
return currentWind;
|
||||
private Wind changeWind(Wind wind) {
|
||||
Wind newWind = new Wind(wind.getWindDirection(), wind.getWindSpeed());
|
||||
oscillateWind(newWind);
|
||||
shiftWind(newWind);
|
||||
changeWindSpeed(newWind);
|
||||
return newWind;
|
||||
}
|
||||
|
||||
private Wind oscillateWind(Wind currentWind) {
|
||||
return currentWind;
|
||||
private void oscillateWind(Wind wind) {
|
||||
double timeSinceLastOscillationReset = System.currentTimeMillis() - timeOfLastOscillationReset;
|
||||
if (oscillationLeft) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Wind shiftWind(Wind currentWind) {
|
||||
return currentWind;
|
||||
private void shiftWind(Wind wind) {
|
||||
}
|
||||
|
||||
public void setMaxBearingVariance(double maxBearingVariance) {
|
||||
this.maxBearingVariance = maxBearingVariance;
|
||||
private void changeWindSpeed(Wind wind) {
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user