Added scaler variable to mulitply the race clock and the boats' velocities by
- Races take roughly 15 mins realtime with a slowest boat of ~20 knots. Therefore scale by 3 for a 5 min race, and 15 for a 1 min race #story[16] #implement
This commit is contained in:
@@ -25,12 +25,12 @@ public class Constants {
|
||||
public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260);
|
||||
|
||||
public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[]
|
||||
{new BoatInRace("Oracle Team USA", 300.0, Color.BLUEVIOLET, "USA"),
|
||||
new BoatInRace("Land Rover BAR", 500.0, Color.BLACK, "BAR"),
|
||||
new BoatInRace("SoftBank Team Japan", 400.0, Color.RED, "JAP"),
|
||||
new BoatInRace("Groupama Team France", 350.0, Color.ORANGE, "FRN"),
|
||||
new BoatInRace("Artemis Racing", 440.0, Color.DARKOLIVEGREEN, "ART"),
|
||||
new BoatInRace("Emirates Team New Zealand", 620, Color.LIMEGREEN, "ENZ")};
|
||||
{new BoatInRace("Oracle Team USA", 30.0, Color.BLUEVIOLET, "USA"),
|
||||
new BoatInRace("Land Rover BAR", 23.0, Color.BLACK, "BAR"),
|
||||
new BoatInRace("SoftBank Team Japan", 27.0, Color.RED, "JAP"),
|
||||
new BoatInRace("Groupama Team France", 25.0, Color.ORANGE, "FRN"),
|
||||
new BoatInRace("Artemis Racing", 22.5, Color.DARKOLIVEGREEN, "ART"),
|
||||
new BoatInRace("Emirates Team New Zealand", 62, Color.LIMEGREEN, "ENZ")};
|
||||
|
||||
//public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new )
|
||||
}
|
||||
|
||||
@@ -12,7 +12,9 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class Boat {
|
||||
private StringProperty name;
|
||||
|
||||
private double velocity;
|
||||
private double scaledVelocity;
|
||||
private StringProperty velocityProp;
|
||||
private String abbrev;
|
||||
|
||||
@@ -48,6 +50,15 @@ public class Boat {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
|
||||
public double getScaledVelocity() {
|
||||
return scaledVelocity;
|
||||
}
|
||||
|
||||
public void setScaledVelocity(double velocity) {
|
||||
this.scaledVelocity = velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The Name of the boat.
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ConstantVelocityRace extends Race {
|
||||
protected void updatePosition(BoatInRace boat, int millisecondsElapsed) {
|
||||
|
||||
//distanceTravelled = velocity (nm p hr) * time taken to update loop
|
||||
double distanceTravelled = boat.getVelocity() * millisecondsElapsed/3600000;
|
||||
double distanceTravelled = boat.getScaledVelocity() * millisecondsElapsed/3600000;
|
||||
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
||||
|
||||
boolean finish = boat.getCurrentLeg().getName().equals("Finish");
|
||||
|
||||
@@ -28,6 +28,7 @@ public class Leg {
|
||||
this.endGPSCoordinate = end;
|
||||
this.legNumber = number;
|
||||
this.distance = calculateDistance();
|
||||
System.out.println("Distance of leg " + name + " is " + Double.toString(distance));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ public abstract class Race implements Runnable {
|
||||
protected RaceController controller;
|
||||
protected int boatsFinished = 0;
|
||||
protected long totalTimeElapsed;
|
||||
protected int scale_factor = 15;
|
||||
|
||||
|
||||
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
||||
@@ -34,6 +35,10 @@ public abstract class Race implements Runnable {
|
||||
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
||||
*/
|
||||
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
|
||||
for (BoatInRace boat : boats) {
|
||||
boat.setScaledVelocity(boat.getVelocity() * scale_factor);
|
||||
}
|
||||
|
||||
this.startingBoats = FXCollections.observableArrayList(boats);
|
||||
this.legs = legs;
|
||||
this.legs.add(new Leg("Finish", this.legs.size()));
|
||||
@@ -117,8 +122,9 @@ public abstract class Race implements Runnable {
|
||||
long hours;
|
||||
|
||||
currentTimeInSeconds = totalTimeElapsed / 1000;
|
||||
minutes = currentTimeInSeconds / 60;
|
||||
remainingSeconds = currentTimeInSeconds % 60;
|
||||
long scaledTimeInSeconds = currentTimeInSeconds * scale_factor;
|
||||
minutes = scaledTimeInSeconds / 60;
|
||||
remainingSeconds = scaledTimeInSeconds % 60;
|
||||
hours = minutes / 60;
|
||||
minutes = minutes % 60;
|
||||
return String.format("Race clock: %02d:%02d:%02d", hours, minutes, remainingSeconds);
|
||||
|
||||
Reference in New Issue
Block a user