Merge branch 'master' into story68

-updated port and starboard boat checks
-added gps method to check if on correct side of a line
-updated pos check method to make boats round marks with the new tech

# Conflicts:
#	racevisionGame/src/main/java/mock/app/ConnectionAcceptor.java
#	racevisionGame/src/main/java/mock/app/Event.java
#	racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java
#	racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java
This commit is contained in:
hba56
2017-08-12 03:26:28 +12:00
parent 499a409d4f
commit d70a711a3d
7 changed files with 87 additions and 34 deletions
@@ -211,11 +211,22 @@ public class MockBoat extends Boat {
* @return true if mark is on port side
*/
public boolean isPortSide(Mark mark){
//if this boat is lower than the mark check which way it is facing
if(this.getCurrentPosition().getLongitude() < mark.getPosition().getLongitude()){
Bearing towardsMark = GPSCoordinate.calculateBearing(this.getCurrentPosition(), mark.getPosition());
if (towardsMark.degrees() > 315 || towardsMark.degrees() <= 45){
//south quadrant
return this.getBearing().degrees() <= 180;
} else if(towardsMark.degrees() > 45 && towardsMark.degrees() <= 135){
//west quadrant
return (this.getBearing().degrees() <= 270 && this.getBearing().degrees() >= 90);
}else if(towardsMark.degrees() > 135 && towardsMark.degrees() <= 225){
//north quadrant
return this.getBearing().degrees() >= 180;
}else if(towardsMark.degrees() > 225 && towardsMark.degrees() <= 315){
//east quadrant
return (this.getBearing().degrees() <= 90 || this.getBearing().degrees() >= 270);
}else{
return this.getBearing().degrees() > 180;
//should not reach here
return false;
}
}
@@ -226,10 +237,22 @@ public class MockBoat extends Boat {
*/
public boolean isStarboardSide(Mark mark){
//if this boat is lower than the mark check which way it is facing
if(this.getCurrentPosition().getLongitude() < mark.getPosition().getLongitude()){
return this.getBearing().degrees() >= 180;
Bearing towardsMark = GPSCoordinate.calculateBearing(this.getCurrentPosition(), mark.getPosition());
if (towardsMark.degrees() > 315 || towardsMark.degrees() <= 45){
//south quadrant
return !(this.getBearing().degrees() <= 180);
} else if(towardsMark.degrees() > 45 && towardsMark.degrees() <= 135){
//west quadrant
return !(this.getBearing().degrees() <= 270 && this.getBearing().degrees() >= 90);
}else if(towardsMark.degrees() > 135 && towardsMark.degrees() <= 225){
//north quadrant
return !(this.getBearing().degrees() >= 180);
}else if(towardsMark.degrees() > 225 && towardsMark.degrees() <= 315){
//east quadrant
return !(this.getBearing().degrees() <= 90 || this.getBearing().degrees() >= 270);
}else{
return this.getBearing().degrees() < 180;
//should not reach here
return false;
}
}
@@ -3,12 +3,10 @@ package mock.model;
import network.Messages.Enums.BoatStatusEnum;
import network.Messages.Enums.RaceStatusEnum;
import network.Messages.LatestMessages;
import org.opengis.geometry.primitive.*;
import shared.dataInput.BoatDataSource;
import shared.dataInput.RaceDataSource;
import shared.dataInput.RegattaDataSource;
import shared.model.*;
import shared.model.Bearing;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
@@ -321,6 +319,8 @@ public class MockRace extends Race {
if (!finish && totalElapsedMilliseconds >= updatePeriodMilliseconds) {
checkPosition(boat, totalElapsedMilliseconds);
if (boat.getCurrentSpeed() == 0) {
newOptimalVMG(boat);
boat.setBearing(boat.calculateBearingToNextMarker());
@@ -467,22 +467,22 @@ public class MockRace extends Race {
* @param boat the boat that is rounding a mark
* @param roundingChecks the checks to run
*/
private void boatRoundingCheckPort(MockBoat boat, List<GPSCoordinate> roundingChecks){
private void boatRoundingCheckPort(MockBoat boat, List<GPSCoordinate> roundingChecks, Bearing legBearing){
//boats must pass all checks in order to round a mark
switch (boat.getRoundingStatus()) {
case 0://hasn't started rounding
// System.out.println("round 0");
if (boat.isPortSide(boat.getCurrentLeg().getEndCompoundMark().getMark1()) &&
GPSCoordinate.intersects(boat.getCurrentLeg().getEndCompoundMark().getMark1().getPosition(),
roundingChecks.get(0), boat.getCurrentPosition())) {
if (boat.isPortSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) &&
GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(),
roundingChecks.get(0), boat.getCurrentPosition(), legBearing)) {
System.out.println("true");
boat.increaseRoundingStatus();
}
break;
case 1://has been parallel to the mark
// System.out.println("round 1");
if (boat.isPortSide(boat.getCurrentLeg().getEndCompoundMark().getMark1()) &&
GPSCoordinate.intersects(boat.getCurrentLeg().getEndCompoundMark().getMark1().getPosition(),
roundingChecks.get(1), boat.getCurrentPosition())) {
if (boat.isPortSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) &&
GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(),
roundingChecks.get(1), boat.getCurrentPosition(), Bearing.fromDegrees(legBearing.degrees() - 90))) {//negitive 90 from bearing because of port rounding
boat.increaseRoundingStatus();
}
break;
@@ -533,7 +533,6 @@ public class MockRace extends Race {
* @param timeElapsed The total time, in milliseconds, that has elapsed since the race started.
*/
protected void checkPosition(MockBoat boat, long timeElapsed) {
//The distance, in nautical miles, within which the boat needs to get in order to consider that it has reached the marker.
double epsilonNauticalMiles = 250.0 / Constants.NMToMetersConversion; //250 meters.
@@ -541,17 +540,15 @@ public class MockRace extends Race {
//Boat is within an acceptable distance from the mark.
GPSCoordinate startDirectionLinePoint = boat.getCurrentLeg().getStartCompoundMark().getMark1Position();
//todo will need to change this for gates, so that the end point is the side of the gate needed to be rounded
GPSCoordinate endDirectionLinePoint = boat.getCurrentLeg().getEndCompoundMark().getMark1Position();
Bearing bearingOfDirectionLine = GPSCoordinate.calculateBearing(startDirectionLinePoint, endDirectionLinePoint);
//use the direction line to create three invisible points that act as crossover lines a boat must cross
//to round a mark
GPSCoordinate roundCheck1 = GPSCoordinate.calculateNewPosition(startDirectionLinePoint,
GPSCoordinate roundCheck1 = GPSCoordinate.calculateNewPosition(endDirectionLinePoint,
epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfDirectionLine.degrees() + 90));//adding 90 so the check line is parallel
GPSCoordinate roundCheck2 = GPSCoordinate.calculateNewPosition(startDirectionLinePoint,
GPSCoordinate roundCheck2 = GPSCoordinate.calculateNewPosition(endDirectionLinePoint,
epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfDirectionLine.degrees()));
List<GPSCoordinate> roundingChecks = new ArrayList<GPSCoordinate>(Arrays.asList(roundCheck1, roundCheck2));
@@ -559,7 +556,7 @@ public class MockRace extends Race {
switch (boat.getCurrentLeg().getEndCompoundMark().getRoundingType()) {
case SP://Not yet implemented so these gates will be rounded port side
case Port:
boatRoundingCheckPort(boat, roundingChecks);
boatRoundingCheckPort(boat, roundingChecks, bearingOfDirectionLine);
break;
case PS://not yet implemented so these gates will be rounded starboard side
case Starboard: