diff --git a/mock/src/main/java/seng302/Model/Race.java b/mock/src/main/java/seng302/Model/Race.java index 460c1386..b35c0487 100644 --- a/mock/src/main/java/seng302/Model/Race.java +++ b/mock/src/main/java/seng302/Model/Race.java @@ -33,7 +33,7 @@ public class Race implements Runnable { protected List legs; protected int boatsFinished = 0; protected long totalTimeElapsed; - protected int scaleFactor = 3; + protected int scaleFactor = 15; private long startTime; private int raceId; 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.windDirection = 180; + + } /** @@ -257,11 +259,7 @@ public class Race implements Runnable { double totalDistanceTravelledInTack = distanceTravelled + 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); @@ -273,23 +271,19 @@ public class Race implements Runnable { 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. - bound1 = boat.getHeading() - turnAngle; - bound2 = boat.getHeading() + turnAngle; + double bound1 = boat.getHeading() - turnAngle; + double bound2 = boat.getHeading() + turnAngle; + //The bounds cap out at [0, 360). bound1 = Math.max(bound1, 0); bound2 = Math.min(bound2, 360); + //Calculate the new VMG. VMG newHeading = boat.getPolars().calculateVMG(this.windDirection, this.windSpeed, 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? @@ -297,21 +291,27 @@ public class Race implements Runnable { double angleBetweenDestAndNewVMG = newHeading.getBearing() - boat.calculateBearingToDestination(); double currentVelocity = cos(Math.toRadians(angleBetweenDestAndHeading)) * boat.getVelocity(); 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) { boat.setHeading(newHeading.getBearing()); boat.setVelocity(newHeading.getSpeed()); 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.getVelocity() + " 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 //double angleBetweenDestAndHeading = boat.getHeading() - boat.calculateBearingToDestination(); @@ -320,7 +320,7 @@ public class Race implements Runnable { //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) { azimuth = azimuth - 360; } diff --git a/mock/src/main/java/seng302/Model/VMG.java b/mock/src/main/java/seng302/Model/VMG.java index 547f8206..dbc2b89a 100644 --- a/mock/src/main/java/seng302/Model/VMG.java +++ b/mock/src/main/java/seng302/Model/VMG.java @@ -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. */ public double getSpeed() {