- 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;
|
//package seng302;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* Created by fwy13 on 3/03/17.
|
// * Created by fwy13 on 3/03/17.
|
||||||
*/
|
// */
|
||||||
public class Event {
|
//public class Event {
|
||||||
private RaceMarker raceMarker;
|
// private Leg leg;
|
||||||
private Boat boat;
|
// private Boat boat;
|
||||||
private int time;
|
// private int time;
|
||||||
private RaceMarker goalMarker;
|
// private Leg goalMarker;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Initaliser for Racemaker without a goal node (such as the Finish line).
|
// * Initaliser for Racemaker without a goal node (such as the Finish line).
|
||||||
* @param raceMarker current Racemarker that has just been passed.
|
// * @param leg current Racemarker that has just been passed.
|
||||||
* @param boat Boat that has been passed.
|
// * @param boat Boat that has been passed.
|
||||||
* @param time time in seconds that the event occurred.
|
// * @param time time in seconds that the event occurred.
|
||||||
* @see seng302.RaceMarker
|
// * @see Leg
|
||||||
* @see seng302.Boat
|
// * @see seng302.Boat
|
||||||
*/
|
// */
|
||||||
public Event(RaceMarker raceMarker, Boat boat, int time){
|
// public Event(Leg leg, Boat boat, int time){
|
||||||
this.raceMarker = raceMarker;
|
// this.leg = leg;
|
||||||
this.boat = boat;
|
// this.boat = boat;
|
||||||
this.time = time;
|
// this.time = time;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Initaliser for Racemaker with a goal node.
|
// * Initaliser for Racemaker with a goal node.
|
||||||
* @param raceMarker current Racemarker that has just been passed.
|
// * @param leg current Racemarker that has just been passed.
|
||||||
* @param boat Boat that has been passed.
|
// * @param boat Boat that has been passed.
|
||||||
* @param time time in seconds that the event occurred.
|
// * @param time time in seconds that the event occurred.
|
||||||
* @param goalMarker the next marker that the boat is aiming for.
|
// * @param goalMarker the next marker that the boat is aiming for.
|
||||||
* @see seng302.RaceMarker
|
// * @see Leg
|
||||||
* @see seng302.Boat
|
// * @see seng302.Boat
|
||||||
*/
|
// */
|
||||||
public Event(RaceMarker raceMarker, Boat boat, int time, RaceMarker goalMarker){
|
// public Event(Leg leg, Boat boat, int time, Leg goalMarker){
|
||||||
this.raceMarker = raceMarker;
|
// this.leg = leg;
|
||||||
this.boat = boat;
|
// this.boat = boat;
|
||||||
this.time = time;
|
// this.time = time;
|
||||||
this.goalMarker = goalMarker;
|
// this.goalMarker = goalMarker;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
//
|
||||||
* Calculates the bearing of the travel via map coordinates of the raceMarkers
|
// /**
|
||||||
* @return
|
// *
|
||||||
*/
|
// * @return the leg that the boat has just passed.
|
||||||
public double calculateHeading(){
|
// */
|
||||||
//to be changed to coordinates when used to match reality.
|
// public Leg getLeg() {
|
||||||
double thetaHat = Math.atan2((goalMarker.getLatitude() - raceMarker.getLatitude()), (goalMarker.getLongitude() - raceMarker.getLongitude()));
|
// return leg;
|
||||||
return thetaHat >= 0 ? Math.toDegrees(thetaHat): Math.toDegrees(thetaHat + 2 * Math.PI);
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
/**
|
// *
|
||||||
*
|
// * @return the boat that this event occured for.
|
||||||
* @return the raceMarker that the boat has just passed.
|
// */
|
||||||
*/
|
// public Boat getBoat() {
|
||||||
public RaceMarker getRaceMarker() {
|
// return boat;
|
||||||
return raceMarker;
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
/**
|
// *
|
||||||
*
|
// * @return the time the event occurred
|
||||||
* @return the boat that this event occured for.
|
// */
|
||||||
*/
|
// public int getTime(){
|
||||||
public Boat getBoat() {
|
// return this.time;
|
||||||
return boat;
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
/**
|
// *
|
||||||
*
|
// * @return the event as a string in format {Boat Name} passed {Leg Name} at {Time Event Occurred} seconds at heading {Heading}.
|
||||||
* @return the time the event occurred
|
// */
|
||||||
*/
|
// public String toString() {
|
||||||
public int getTime(){
|
// String stringToReturn = boat.getName() + " passed " + leg.toString() + " at " + time + " seconds";
|
||||||
return this.time;
|
// if (goalMarker != null){
|
||||||
}
|
// stringToReturn += " at heading " + (int) calculateHeading();
|
||||||
|
// }
|
||||||
/**
|
// stringToReturn += ".";
|
||||||
*
|
// return stringToReturn;
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,38 +1,38 @@
|
|||||||
package seng302;
|
//package seng302;
|
||||||
|
//
|
||||||
import java.util.Collections;
|
//import java.util.Collections;
|
||||||
import java.util.Random;
|
//import java.util.Random;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* Created by cbt24 on 6/03/17.
|
// * Created by cbt24 on 6/03/17.
|
||||||
*/
|
// */
|
||||||
public class RandomisedRace extends Race {
|
//public class RandomisedRace extends Race {
|
||||||
/**
|
// /**
|
||||||
* Randomise race, this is a race that the boats cross each mark randomly, and is a extension of Race.
|
// * Randomise race, this is a race that the boats cross each mark randomly, and is a extension of Race.
|
||||||
* @param boats
|
// * @param boats
|
||||||
* @param marks
|
// * @param marks
|
||||||
* @param timescale
|
// * @param timescale
|
||||||
* @see seng302.Race
|
// * @see seng302.Race
|
||||||
*/
|
// */
|
||||||
public RandomisedRace(Boat[] boats, RaceMarker[] marks, int timescale) {
|
// public RandomisedRace(Boat[] boats, Leg[] marks, int timescale) {
|
||||||
super(boats, marks, timescale);
|
// super(boats, marks, timescale);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Generates the Race to be reported when Simulate Race in the Race class is called.
|
// * Generates the Race to be reported when Simulate Race in the Race class is called.
|
||||||
* @see Race#simulateRace()
|
// * @see Race#simulateRace()
|
||||||
*/
|
// */
|
||||||
protected void generateRace() {
|
// protected void generateRace() {
|
||||||
Random rand = new Random();
|
// Random rand = new Random();
|
||||||
for (Boat boat: this.boats){
|
// for (Boat boat: this.boats){
|
||||||
events.add(new Event(new RaceMarker("Start", 0, 0, 0), boat, 0));
|
// events.add(new Event(new Leg("Start", 0, 0, 0), boat, 0));
|
||||||
int prevTime = 0;
|
// int prevTime = 0;
|
||||||
for (RaceMarker raceMarker: marks){
|
// for (Leg raceMarker: marks){
|
||||||
int time = rand.nextInt(12) + 6;
|
// int time = rand.nextInt(12) + 6;
|
||||||
events.add(new Event(raceMarker, boat, prevTime + time));
|
// events.add(new Event(raceMarker, boat, prevTime + time));
|
||||||
prevTime += time;
|
// prevTime += time;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
Collections.sort(events, (o1, o2) -> o1.getTime() - o2.getTime());
|
// Collections.sort(events, (o1, o2) -> o1.getTime() - o2.getTime());
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
Loading…
Reference in new issue