parent
4f6ab7b4bc
commit
7c0d9203a5
@ -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());
|
||||
}
|
||||
}
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue