- Event has been replaced by leg, which holds the start and end coordinates, and total distance needed to pass it. - The boats coordinates will be recalculated at each run through of the loop - Not worrying about randomised race for now. #refactormain
parent
54d4ea2d03
commit
b73fee2cb5
@ -0,0 +1,41 @@
|
||||
package seng302;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 15/03/17.
|
||||
*/
|
||||
public class BoatInRace extends Boat {
|
||||
|
||||
private Leg currentLeg;
|
||||
|
||||
public Leg getCurrentLeg() {
|
||||
return currentLeg;
|
||||
}
|
||||
|
||||
public double getDistanceTravelledInLeg() {
|
||||
return distanceTravelledInLeg;
|
||||
}
|
||||
|
||||
public Coordinate getCurrentPosition() {
|
||||
return currentPosition;
|
||||
}
|
||||
|
||||
private double distanceTravelledInLeg;
|
||||
private Coordinate currentPosition;
|
||||
|
||||
|
||||
BoatInRace(String name, double velocity) {
|
||||
super(name, velocity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the bearing of the travel via map coordinates of the raceMarkers
|
||||
* @return
|
||||
*/
|
||||
public double calculateHeading(){
|
||||
//to be changed to coordinates when used to match reality.
|
||||
double thetaHat = Math.atan2((currentLeg.getEndCoordinate().getX() - currentPosition.getX()), (currentLeg.getEndCoordinate().getY() - currentPosition.getY()));
|
||||
return thetaHat >= 0 ? Math.toDegrees(thetaHat): Math.toDegrees(thetaHat + 2 * Math.PI);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,88 +1,79 @@
|
||||
package seng302;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 3/03/17.
|
||||
*/
|
||||
public class Event {
|
||||
private RaceMarker raceMarker;
|
||||
private Boat boat;
|
||||
private int time;
|
||||
private RaceMarker goalMarker;
|
||||
|
||||
/**
|
||||
* Initaliser for Racemaker without a goal node (such as the Finish line).
|
||||
* @param raceMarker current Racemarker that has just been passed.
|
||||
* @param boat Boat that has been passed.
|
||||
* @param time time in seconds that the event occurred.
|
||||
* @see seng302.RaceMarker
|
||||
* @see seng302.Boat
|
||||
*/
|
||||
public Event(RaceMarker raceMarker, Boat boat, int time){
|
||||
this.raceMarker = raceMarker;
|
||||
this.boat = boat;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initaliser for Racemaker with a goal node.
|
||||
* @param raceMarker current Racemarker that has just been passed.
|
||||
* @param boat Boat that has been passed.
|
||||
* @param time time in seconds that the event occurred.
|
||||
* @param goalMarker the next marker that the boat is aiming for.
|
||||
* @see seng302.RaceMarker
|
||||
* @see seng302.Boat
|
||||
*/
|
||||
public Event(RaceMarker raceMarker, Boat boat, int time, RaceMarker goalMarker){
|
||||
this.raceMarker = raceMarker;
|
||||
this.boat = boat;
|
||||
this.time = time;
|
||||
this.goalMarker = goalMarker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the bearing of the travel via map coordinates of the raceMarkers
|
||||
* @return
|
||||
*/
|
||||
public double calculateHeading(){
|
||||
//to be changed to coordinates when used to match reality.
|
||||
double thetaHat = Math.atan2((goalMarker.getLatitude() - raceMarker.getLatitude()), (goalMarker.getLongitude() - raceMarker.getLongitude()));
|
||||
return thetaHat >= 0 ? Math.toDegrees(thetaHat): Math.toDegrees(thetaHat + 2 * Math.PI);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the raceMarker that the boat has just passed.
|
||||
*/
|
||||
public RaceMarker getRaceMarker() {
|
||||
return raceMarker;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the boat that this event occured for.
|
||||
*/
|
||||
public Boat getBoat() {
|
||||
return boat;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the time the event occurred
|
||||
*/
|
||||
public int getTime(){
|
||||
return this.time;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the event as a string in format {Boat Name} passed {RaceMarker Name} at {Time Event Occurred} seconds at heading {Heading}.
|
||||
*/
|
||||
public String toString() {
|
||||
String stringToReturn = boat.getName() + " passed " + raceMarker.toString() + " at " + time + " seconds";
|
||||
if (goalMarker != null){
|
||||
stringToReturn += " at heading " + (int) calculateHeading();
|
||||
}
|
||||
stringToReturn += ".";
|
||||
return stringToReturn;
|
||||
}
|
||||
}
|
||||
//package seng302;
|
||||
//
|
||||
///**
|
||||
// * Created by fwy13 on 3/03/17.
|
||||
// */
|
||||
//public class Event {
|
||||
// private Leg leg;
|
||||
// private Boat boat;
|
||||
// private int time;
|
||||
// private Leg goalMarker;
|
||||
//
|
||||
// /**
|
||||
// * Initaliser for Racemaker without a goal node (such as the Finish line).
|
||||
// * @param leg current Racemarker that has just been passed.
|
||||
// * @param boat Boat that has been passed.
|
||||
// * @param time time in seconds that the event occurred.
|
||||
// * @see Leg
|
||||
// * @see seng302.Boat
|
||||
// */
|
||||
// public Event(Leg leg, Boat boat, int time){
|
||||
// this.leg = leg;
|
||||
// this.boat = boat;
|
||||
// this.time = time;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Initaliser for Racemaker with a goal node.
|
||||
// * @param leg current Racemarker that has just been passed.
|
||||
// * @param boat Boat that has been passed.
|
||||
// * @param time time in seconds that the event occurred.
|
||||
// * @param goalMarker the next marker that the boat is aiming for.
|
||||
// * @see Leg
|
||||
// * @see seng302.Boat
|
||||
// */
|
||||
// public Event(Leg leg, Boat boat, int time, Leg goalMarker){
|
||||
// this.leg = leg;
|
||||
// this.boat = boat;
|
||||
// this.time = time;
|
||||
// this.goalMarker = goalMarker;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * @return the leg that the boat has just passed.
|
||||
// */
|
||||
// public Leg getLeg() {
|
||||
// return leg;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * @return the boat that this event occured for.
|
||||
// */
|
||||
// public Boat getBoat() {
|
||||
// return boat;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * @return the time the event occurred
|
||||
// */
|
||||
// public int getTime(){
|
||||
// return this.time;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * @return the event as a string in format {Boat Name} passed {Leg Name} at {Time Event Occurred} seconds at heading {Heading}.
|
||||
// */
|
||||
// public String toString() {
|
||||
// String stringToReturn = boat.getName() + " passed " + leg.toString() + " at " + time + " seconds";
|
||||
// if (goalMarker != null){
|
||||
// stringToReturn += " at heading " + (int) calculateHeading();
|
||||
// }
|
||||
// stringToReturn += ".";
|
||||
// return stringToReturn;
|
||||
// }
|
||||
//}
|
||||
|
||||
@ -1,38 +1,38 @@
|
||||
package seng302;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 6/03/17.
|
||||
*/
|
||||
public class RandomisedRace extends Race {
|
||||
/**
|
||||
* Randomise race, this is a race that the boats cross each mark randomly, and is a extension of Race.
|
||||
* @param boats
|
||||
* @param marks
|
||||
* @param timescale
|
||||
* @see seng302.Race
|
||||
*/
|
||||
public RandomisedRace(Boat[] boats, RaceMarker[] marks, int timescale) {
|
||||
super(boats, marks, timescale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the Race to be reported when Simulate Race in the Race class is called.
|
||||
* @see Race#simulateRace()
|
||||
*/
|
||||
protected void generateRace() {
|
||||
Random rand = new Random();
|
||||
for (Boat boat: this.boats){
|
||||
events.add(new Event(new RaceMarker("Start", 0, 0, 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());
|
||||
}
|
||||
}
|
||||
//package seng302;
|
||||
//
|
||||
//import java.util.Collections;
|
||||
//import java.util.Random;
|
||||
//
|
||||
///**
|
||||
// * Created by cbt24 on 6/03/17.
|
||||
// */
|
||||
//public class RandomisedRace extends Race {
|
||||
// /**
|
||||
// * Randomise race, this is a race that the boats cross each mark randomly, and is a extension of Race.
|
||||
// * @param boats
|
||||
// * @param marks
|
||||
// * @param timescale
|
||||
// * @see seng302.Race
|
||||
// */
|
||||
// public RandomisedRace(Boat[] boats, Leg[] marks, int timescale) {
|
||||
// super(boats, marks, timescale);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Generates the Race to be reported when Simulate Race in the Race class is called.
|
||||
// * @see Race#simulateRace()
|
||||
// */
|
||||
// protected void generateRace() {
|
||||
// Random rand = new Random();
|
||||
// for (Boat boat: this.boats){
|
||||
// events.add(new Event(new Leg("Start", 0, 0, 0), boat, 0));
|
||||
// int prevTime = 0;
|
||||
// for (Leg 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