From f386a4b9898163e9b3cb81e1ee6b8a2474fed83a Mon Sep 17 00:00:00 2001 From: hba56 Date: Sat, 12 Aug 2017 22:27:27 +1200 Subject: [PATCH] added checks for gates and moved second rounding check to be in line with the next mark to move towards #story[1101] --- .../src/main/java/mock/model/MockBoat.java | 1 + .../src/main/java/mock/model/MockRace.java | 41 +++++++++++++++---- .../main/java/shared/model/CompoundMark.java | 13 ++++++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/racevisionGame/src/main/java/mock/model/MockBoat.java b/racevisionGame/src/main/java/mock/model/MockBoat.java index 6fa3fd2b..c623f608 100644 --- a/racevisionGame/src/main/java/mock/model/MockBoat.java +++ b/racevisionGame/src/main/java/mock/model/MockBoat.java @@ -281,6 +281,7 @@ public class MockBoat extends Boat { public void resetRoundingStatus() { this.roundingStatus = 0; } + public boolean isAutoVMG() { return autoVMG; } diff --git a/racevisionGame/src/main/java/mock/model/MockRace.java b/racevisionGame/src/main/java/mock/model/MockRace.java index 32a6a461..71a314c3 100644 --- a/racevisionGame/src/main/java/mock/model/MockRace.java +++ b/racevisionGame/src/main/java/mock/model/MockRace.java @@ -466,14 +466,20 @@ public class MockRace extends Race { * Checks to be run on boats rounding marks on the port side * @param boat the boat that is rounding a mark * @param roundingChecks the checks to run + * @param legBearing the direction of the leg */ - private void boatRoundingCheckPort(MockBoat boat, List roundingChecks, Bearing legBearing){ + private void boatRoundingCheckPort(MockBoat boat, List roundingChecks, Bearing legBearing) { //boats must pass all checks in order to round a mark + + //boolean for if boat has to/needs to pass through a gate + boolean gateCheck = boat.getCurrentLeg().getEndCompoundMark().getMark2() == null || boat.isBetweenGate(boat.getCurrentLeg().getEndCompoundMark()); + switch (boat.getRoundingStatus()) { case 0://hasn't started rounding if (boat.isPortSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) && GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(), - roundingChecks.get(0), boat.getCurrentPosition(), legBearing)) { + roundingChecks.get(0), boat.getCurrentPosition(), legBearing) && + gateCheck) { boat.increaseRoundingStatus(); } break; @@ -499,14 +505,20 @@ public class MockRace extends Race { * Checks to be run on boats rounding marks on the starboard side * @param boat the boat that is rounding a mark * @param roundingChecks the checks to run + * @param legBearing the direction of the leg */ private void boatRoundingCheckStarboard(MockBoat boat, List roundingChecks, Bearing legBearing){ //boats must pass all checks in order to round a mark + + //boolean for if boat has to/needs to pass through a gate + boolean gateCheck = boat.getCurrentLeg().getEndCompoundMark().getMark2() == null || boat.isBetweenGate(boat.getCurrentLeg().getEndCompoundMark()); + switch (boat.getRoundingStatus()) { case 0://hasn't started rounding if (boat.isPortSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) && GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(), - roundingChecks.get(0), boat.getCurrentPosition(), legBearing)) { + roundingChecks.get(0), boat.getCurrentPosition(), legBearing) && + gateCheck) { boat.increaseRoundingStatus(); } break; @@ -533,7 +545,7 @@ public class MockRace extends Race { */ 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. + double epsilonNauticalMiles = boat.getCurrentLeg().getEndCompoundMark().getRoundingDistance(); //250 meters. if (boat.calculateDistanceToNextMarker() < epsilonNauticalMiles) { //Boat is within an acceptable distance from the mark. @@ -545,10 +557,25 @@ public class MockRace extends Race { //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(endDirectionLinePoint, - epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfDirectionLine.degrees() + 90));//adding 90 so the check line is parallel + epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfDirectionLine.degrees() - 90));//adding 90 so the check line is parallel + + GPSCoordinate roundCheck2; + try{ + Leg nextLeg = legs.get(legs.indexOf(boat.getCurrentLeg()) + 1); + + GPSCoordinate startNextDirectionLinePoint = nextLeg.getStartCompoundMark().getMark1Position(); + GPSCoordinate endNextDirectionLinePoint = nextLeg.getEndCompoundMark().getMark1Position(); + Bearing bearingOfNextDirectionLine = GPSCoordinate.calculateBearing(startNextDirectionLinePoint, endNextDirectionLinePoint); + + roundCheck2 = GPSCoordinate.calculateNewPosition(endDirectionLinePoint, + epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfNextDirectionLine.degrees() + 90)); + }catch(NullPointerException e){ + //this is caused by the last leg not being having a leg after it + roundCheck2 = roundCheck1; + } + + - GPSCoordinate roundCheck2 = GPSCoordinate.calculateNewPosition(endDirectionLinePoint, - epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfDirectionLine.degrees())); List roundingChecks = new ArrayList(Arrays.asList(roundCheck1, roundCheck2)); diff --git a/racevisionGame/src/main/java/shared/model/CompoundMark.java b/racevisionGame/src/main/java/shared/model/CompoundMark.java index 05256655..8c1d5eae 100644 --- a/racevisionGame/src/main/java/shared/model/CompoundMark.java +++ b/racevisionGame/src/main/java/shared/model/CompoundMark.java @@ -149,6 +149,19 @@ public class CompoundMark { } + /** + * Used to find how far apart the marks that make up this gate are + * If this compound mark is only one point return base length of 250m + * @return + */ + public double getRoundingDistance(){ + if (mark2 != null){ + return GPSCoordinate.calculateDistanceMeters(mark1.getPosition(), mark2.getPosition()); + }else{ + return 250.0 / Constants.NMToMetersConversion; + } + } + /** * Used to get how this mark should be rounded * @return rounding type for mark