Boats pass marks at times according to boat speed and distance of mark from start.
This commit is contained in:
Generated
+1
-17
@@ -45,26 +45,10 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_3" default="false">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
<component name="SvnConfiguration">
|
<component name="SvnConfiguration">
|
||||||
<configuration>$USER_HOME$/.subversion</configuration>
|
<configuration>$USER_HOME$/.subversion</configuration>
|
||||||
</component>
|
</component>
|
||||||
<component name="masterDetails">
|
|
||||||
<states>
|
|
||||||
<state key="ProjectJDKs.UI">
|
|
||||||
<settings>
|
|
||||||
<last-edited>1.8</last-edited>
|
|
||||||
<splitter-proportions>
|
|
||||||
<option name="proportions">
|
|
||||||
<list>
|
|
||||||
<option value="0.2" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</splitter-proportions>
|
|
||||||
</settings>
|
|
||||||
</state>
|
|
||||||
</states>
|
|
||||||
</component>
|
|
||||||
</project>
|
</project>
|
||||||
@@ -12,16 +12,25 @@ public class App
|
|||||||
test.add(5);
|
test.add(5);
|
||||||
test.add(1, 8);
|
test.add(1, 8);
|
||||||
|
|
||||||
Boat boat1 = new Boat("ORACLE TEAM USA");
|
Boat boat1 = new Boat("ORACLE TEAM USA", 10);
|
||||||
Boat boat2 = new Boat("Artemis Racing");
|
Boat boat2 = new Boat("Artemis Racing", 8);
|
||||||
Boat boat3 = new Boat("Emirates Team New Zealand");
|
Boat boat3 = new Boat("Emirates Team New Zealand", 12);
|
||||||
Boat boat4 = new Boat("Groupama Team France");
|
Boat boat4 = new Boat("Groupama Team France", 11);
|
||||||
Boat boat5 = new Boat("Land Rover BAR");
|
Boat boat5 = new Boat("Land Rover BAR", 10);
|
||||||
Boat boat6 = new Boat("SoftBank Team Japan");
|
Boat boat6 = new Boat("SoftBank Team Japan", 9);
|
||||||
|
|
||||||
|
RaceMarker mark1 = new RaceMarker("Start", 0);
|
||||||
|
RaceMarker mark2 = new RaceMarker("Mark", 120);
|
||||||
|
RaceMarker mark3 = new RaceMarker("Leeward Gate", 240);
|
||||||
|
RaceMarker mark4 = new RaceMarker("Windward Gate", 360);
|
||||||
|
RaceMarker mark5 = new RaceMarker("Leeward Gate", 480);
|
||||||
|
RaceMarker mark6 = new RaceMarker("Finish", 600);
|
||||||
|
|
||||||
Boat[] all_boats = {boat1, boat2, boat3, boat4, boat5, boat6};
|
Boat[] all_boats = {boat1, boat2, boat3, boat4, boat5, boat6};
|
||||||
Boat[] boats = {all_boats[0], all_boats[1]};
|
Boat[] boats = {all_boats[0], all_boats[1]};
|
||||||
|
RaceMarker[] marks = {mark1, mark2, mark3, mark4, mark5, mark6};
|
||||||
|
|
||||||
Race race = new Race(boats);
|
Race race = new ConstantVelocityRace(boats, marks);
|
||||||
race.simulateRace();
|
race.simulateRace();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import java.util.ArrayList;
|
|||||||
*/
|
*/
|
||||||
public class Boat {
|
public class Boat {
|
||||||
private String name;
|
private String name;
|
||||||
|
private double velocity;
|
||||||
|
|
||||||
public Boat(String name){
|
public Boat(String name, double velocity){
|
||||||
|
this.velocity = velocity;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,6 +18,10 @@ public class Boat {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getVelocity() {
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package seng302;
|
||||||
|
|
||||||
|
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);
|
||||||
|
generateRace();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateRace() {
|
||||||
|
for(Boat boat : boats) {
|
||||||
|
for(RaceMarker raceMarker : marks) {
|
||||||
|
events.add(new Event(raceMarker, boat, (int)(raceMarker.getDistance() / boat.getVelocity())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(events, (o1, o2) -> o1.getTime() - o2.getTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,12 +8,12 @@ import java.util.Collections;
|
|||||||
* Created by fwy13 on 3/03/17.
|
* Created by fwy13 on 3/03/17.
|
||||||
*/
|
*/
|
||||||
public class Event {
|
public class Event {
|
||||||
private String name;
|
private RaceMarker raceMarker;
|
||||||
private Boat boat;
|
private Boat boat;
|
||||||
private int time;
|
private int time;
|
||||||
|
|
||||||
public Event(String name, Boat boat, int time){
|
public Event(RaceMarker raceMarker, Boat boat, int time){
|
||||||
this.name = name;
|
this.raceMarker = raceMarker;
|
||||||
this.boat = boat;
|
this.boat = boat;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,6 @@ public class Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return boat.getName() + " passed " + name + " at " + time;
|
return boat.getName() + " passed " + raceMarker.toString() + " at " + time + " seconds.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,16 +8,16 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class Race {
|
public class Race {
|
||||||
Boat[] boats;
|
Boat[] boats;
|
||||||
|
RaceMarker[] marks;
|
||||||
LinkedList<Event> events = new LinkedList<Event>();
|
LinkedList<Event> events = new LinkedList<Event>();
|
||||||
|
|
||||||
public Race(Boat[] boats){
|
public Race(Boat[] boats, RaceMarker[] marks){
|
||||||
this.boats = boats;
|
this.boats = boats;
|
||||||
|
this.marks = marks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void simulateRace(){
|
public void simulateRace(){
|
||||||
String[] marks = {"Mark", "Leeward Gate", "Windward Gate", "Leeward Gate", "Finish"};
|
//printRace()
|
||||||
randomiseRace(marks);
|
|
||||||
//printRace();
|
|
||||||
for (Event event: events) {
|
for (Event event: events) {
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
timer.schedule(new TimerTask(){
|
timer.schedule(new TimerTask(){
|
||||||
@@ -25,22 +25,8 @@ public class Race {
|
|||||||
public void run(){
|
public void run(){
|
||||||
System.out.println(event);
|
System.out.println(event);
|
||||||
}
|
}
|
||||||
}, event.getTime() * 1000);
|
}, event.getTime() * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void randomiseRace(String[] eventNames){
|
|
||||||
Random rand = new Random();
|
|
||||||
for (Boat boat: this.boats){
|
|
||||||
events.add(new Event("Start", boat, 0));
|
|
||||||
int prevTime = 0;
|
|
||||||
for (String markName: eventNames){
|
|
||||||
int time = rand.nextInt(12) + 6;
|
|
||||||
events.add(new Event(markName, boat, prevTime + time));
|
|
||||||
prevTime += time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.sort(events, (o1, o2) -> o1.getTime() - o2.getTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package seng302;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by cbt24 on 6/03/17.
|
||||||
|
*/
|
||||||
|
public class RaceMarker {
|
||||||
|
String name;
|
||||||
|
double distance;
|
||||||
|
|
||||||
|
public RaceMarker(String name, double distance) {
|
||||||
|
this.name = name;
|
||||||
|
this.distance = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDistance() {
|
||||||
|
return distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package seng302;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
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);
|
||||||
|
generateRace();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateRace() {
|
||||||
|
Random rand = new Random();
|
||||||
|
for (Boat boat: this.boats){
|
||||||
|
events.add(new Event(new RaceMarker("Start", 0), boat, 0));
|
||||||
|
int prevTime = 0;
|
||||||
|
for (RaceMarker raceMarker: marks){
|
||||||
|
int time = rand.nextInt(12) + 6;
|
||||||
|
events.add(new Event(raceMarker, boat, prevTime + time));
|
||||||
|
prevTime += time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(events, (o1, o2) -> o1.getTime() - o2.getTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user