Merge branch 'story31.2_alternateTack' into sp4_s31_cleanups

# Conflicts:
#	mock/src/main/java/seng302/Model/Race.java
Resolved conflict manually.
main
fjc40 9 years ago
commit aa7337dc6c

@ -33,7 +33,7 @@ public class Race implements Runnable {
protected List<Leg> legs; protected List<Leg> legs;
protected int boatsFinished = 0; protected int boatsFinished = 0;
protected long totalTimeElapsed; protected long totalTimeElapsed;
protected int scaleFactor = 3; protected int scaleFactor = 15;
private long startTime; private long startTime;
private int raceId; private int raceId;
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
@ -63,6 +63,8 @@ public class Race implements Runnable {
this.windSpeed = 12;//TODO could use input parameters for these. And should fluctuate during race. this.windSpeed = 12;//TODO could use input parameters for these. And should fluctuate during race.
this.windDirection = 180; this.windDirection = 180;
} }
/** /**
@ -256,11 +258,7 @@ public class Race implements Runnable {
double totalDistanceTravelledInTack = distanceTravelled;//TODO FIX// + boat.getDistanceTravelledInTack(); double totalDistanceTravelledInTack = distanceTravelled;//TODO FIX// + boat.getDistanceTravelledInTack();
double bound1 = (boat.calculateBearingToDestination() - 90) % 360;
double bound2 = (boat.calculateBearingToDestination() + 90) % 360;
//TODO the actual bearing bounds need to be the interval in which the boat won't go out of bounds.
bound1 = 0;
bound2 = 360;
boat.setTimeSinceTackChange(boat.getTimeSinceTackChange() + this.scaleFactor * millisecondsElapsed); boat.setTimeSinceTackChange(boat.getTimeSinceTackChange() + this.scaleFactor * millisecondsElapsed);
@ -272,23 +270,19 @@ public class Race implements Runnable {
double turnAngle = turnRate * boat.getTimeSinceTackChange(); double turnAngle = turnRate * boat.getTimeSinceTackChange();
//System.out.println("boat " + boat.getAbbrev() + " turn angle is " + turnAngle + ".");//TEMP DEBUG REMOVE
//Find the bounds on what angle the boat is allowed to travel at. //Find the bounds on what angle the boat is allowed to travel at.
bound1 = boat.getHeading() - turnAngle; double bound1 = boat.getHeading() - turnAngle;
bound2 = boat.getHeading() + turnAngle; double bound2 = boat.getHeading() + turnAngle;
//The bounds cap out at [0, 360). //The bounds cap out at [0, 360).
bound1 = Math.max(bound1, 0); bound1 = Math.max(bound1, 0);
bound2 = Math.min(bound2, 360); bound2 = Math.min(bound2, 360);
//Calculate the new VMG.
VMG newHeading = boat.getPolars().calculateVMG(this.windDirection, this.windSpeed, VMG newHeading = boat.getPolars().calculateVMG(this.windDirection, this.windSpeed,
boat.calculateBearingToDestination(), bound1, bound2); boat.calculateBearingToDestination(), bound1, bound2);
if (!GPSCoordinate.isInsideBoundary(boat.getCurrentPosition(), boundary)){
double tempHeading = (newHeading.getBearing() - this.windDirection +90)%360;
newHeading.setBearing(tempHeading);
}
//Is this new VMG better than the current VMG? //Is this new VMG better than the current VMG?
@ -296,21 +290,27 @@ public class Race implements Runnable {
double angleBetweenDestAndNewVMG = newHeading.getBearing() - boat.calculateBearingToDestination(); double angleBetweenDestAndNewVMG = newHeading.getBearing() - boat.calculateBearingToDestination();
double currentVelocity = cos(Math.toRadians(angleBetweenDestAndHeading)) * boat.getCurrentSpeed(); double currentVelocity = cos(Math.toRadians(angleBetweenDestAndHeading)) * boat.getCurrentSpeed();
double vmgVelocity = cos(Math.toRadians(angleBetweenDestAndNewVMG)) * newHeading.getSpeed(); double vmgVelocity = cos(Math.toRadians(angleBetweenDestAndNewVMG)) * newHeading.getSpeed();
//System.out.println("boat " + boat.getAbbrev() + " current velocity is " + currentVelocity + " knots, possible VMG is " + vmgVelocity + " knots.");//TEMP DEBUG REMOVE
if (vmgVelocity > currentVelocity) { if (vmgVelocity > currentVelocity) {
boat.setHeading(newHeading.getBearing()); boat.setHeading(newHeading.getBearing());
boat.setCurrentSpeed(newHeading.getSpeed()); boat.setCurrentSpeed(newHeading.getSpeed());
boat.setTimeSinceTackChange(0); boat.setTimeSinceTackChange(0);
//System.out.println("boat " + boat.getAbbrev() + " has a new bearing " + boat.getHeading() + " degrees, and is " + boat.calculateDistanceToNextMarker() + " nautical miles to the next marker. Velocity to next marker is " + boat.getCurrentSpeed() + " knots.");//TEMP DEBUG REMOVE
} }
double azimuth = boat.getHeading();
if (azimuth > 180) {
azimuth = azimuth - 360;
}
//tests to see if a point in front of the boat is out of bounds, if so mirror heading in the wind
GPSCoordinate test = calculatePosition(boat.getCurrentPosition(), (100.0 / Constants.NMToMetersConversion), azimuth);
if (!GPSCoordinate.isInsideBoundary(test, boundary)) {
double tempHeading = (boat.getHeading() - this.windDirection + 90) % 360;
boat.setHeading(tempHeading);
}
//TODO one way to fix the boat's rapid turning it to only update the velocity/heading every X seconds (e.g., every 5 seconds).
//TODO may need a lower tack period
//TODO another way would be to allow boats use a better VMG if it is within turnRate * timeSinceTackChange. E.g., after 100ms a boat can select a more optimal VMG within 5deg of their current bearing. After 500ms VMG can be within 25deg of current bearing. After 2sec it can be 100deg of bearing, etc...
//calc the distance travelled in a straight line to windward //calc the distance travelled in a straight line to windward
//double angleBetweenDestAndHeading = boat.getHeading() - boat.calculateBearingToDestination(); //double angleBetweenDestAndHeading = boat.getHeading() - boat.calculateBearingToDestination();
@ -319,7 +319,7 @@ public class Race implements Runnable {
//Calculate boat's new position by adding the distance travelled onto the start point of the leg //Calculate boat's new position by adding the distance travelled onto the start point of the leg
double azimuth = boat.getHeading(); azimuth = boat.getHeading();
if (azimuth > 180) { if (azimuth > 180) {
azimuth = azimuth - 360; azimuth = azimuth - 360;
} }

@ -32,7 +32,7 @@ public class VMG {
/** /**
* Returns the speed component of this VMG object, measured in. * Returns the speed component of this VMG object, measured in knots.
* @return Speed component of this VMG object. * @return Speed component of this VMG object.
*/ */
public double getSpeed() { public double getSpeed() {

Loading…
Cancel
Save