Allow users to choose timescale of race playback. Playback is ~1 min by default, real-time selected with command line variable '-5'. Rescaled race marker positions to distances appropriate for a ~5 minute race.

This commit is contained in:
Connor Taylor-Brown
2017-03-08 19:00:09 +13:00
parent b1f588248b
commit 1a9cf5bdda
4 changed files with 25 additions and 19 deletions
+15 -12
View File
@@ -4,25 +4,28 @@ public class App
{
public static void main( String[] args )
{
int factor = 200; // Scale 5 min to 1 min
if(args.length > 0 && args[0].equals("-5")) factor = 1000; // 1:1 scale
Boat[] boats = {
new Boat("ORACLE TEAM USA", 10),
new Boat("Artemis Racing", 8),
new Boat("ORACLE TEAM USA", 11),
new Boat("Artemis Racing", 10),
new Boat("Emirates Team New Zealand", 12),
new Boat("Groupama Team France", 11),
new Boat("Land Rover BAR", 10),
new Boat("SoftBank Team Japan", 9)
new Boat("Groupama Team France", 11.5),
new Boat("Land Rover BAR", 11),
new Boat("SoftBank Team Japan", 10.5)
};
RaceMarker[] marks = {
new RaceMarker("Start", 0, 0, 59),
new RaceMarker("Mark", 72, 72, 50),
new RaceMarker("Leeward Gate", 193, 126, 158),
new RaceMarker("Windward Gate", 373, 41, 0),
new RaceMarker("Leeward Gate", 553, 126, 158),
new RaceMarker("Finish", 607, 95, 203)
new RaceMarker("Start", 0, 0, 295),
new RaceMarker("Mark", 360, 360, 250),
new RaceMarker("Leeward Gate", 965, 630, 790),
new RaceMarker("Windward Gate", 1865, 205, 0),
new RaceMarker("Leeward Gate", 2765, 630, 790),
new RaceMarker("Finish", 3035, 475, 1015)
};
Race race = new ConstantVelocityRace(boats, marks);
Race race = new ConstantVelocityRace(boats, marks, factor);
race.simulateRace();
}
}
@@ -6,8 +6,8 @@ import java.util.Collections;
* Created by cbt24 on 6/03/17.
*/
public class ConstantVelocityRace extends Race {
public ConstantVelocityRace(Boat[] boats, RaceMarker[] marks) {
super(boats, marks);
public ConstantVelocityRace(Boat[] boats, RaceMarker[] marks, int factor) {
super(boats, marks, factor);
generateRace();
}
+6 -3
View File
@@ -9,12 +9,15 @@ import java.util.*;
public class Race {
Boat[] boats;
RaceMarker[] marks;
int factor;
LinkedList<Event> events = new LinkedList<Event>();
Timer timer = new Timer();
public Race(Boat[] boats, RaceMarker[] marks){
public Race(Boat[] boats, RaceMarker[] marks, int factor) {
this.boats = boats;
this.marks = marks;
this.factor = factor;
}
public void simulateRace(){
@@ -34,7 +37,7 @@ public class Race {
public void run(){
System.out.println(event);
}
}, event.getTime() * 1000);
}, event.getTime() * factor);
}
/*
@@ -55,7 +58,7 @@ public class Race {
}
}
}
}, (events.getLast().getTime() + 1) * 1000);
}, (events.getLast().getTime() + 1) * factor);
}
}
+2 -2
View File
@@ -7,8 +7,8 @@ import java.util.Random;
* Created by cbt24 on 6/03/17.
*/
public class RandomisedRace extends Race {
public RandomisedRace(Boat[] boats, RaceMarker[] marks) {
super(boats, marks);
public RandomisedRace(Boat[] boats, RaceMarker[] marks, int factor) {
super(boats, marks, factor);
generateRace();
}