From 27cf0e153994a084dd547c4176ac0dcd095e332f Mon Sep 17 00:00:00 2001 From: Joseph Gardner Date: Wed, 2 Aug 2017 16:31:55 +1200 Subject: [PATCH 1/7] Started splitting MockRace into RaceLogic and RaceState. #refactor #story[1094] --- .../src/main/java/mock/model/MockRace.java | 10 - .../src/main/java/mock/model/RaceLogic.java | 73 +++ .../src/main/java/mock/model/RaceState.java | 156 ++++- .../src/main/java/mock/model/SplitTODO.java | 555 ++++++++++++++++++ .../src/main/java/shared/model/Race.java | 6 +- .../gameController/ControllerServer.java | 10 +- 6 files changed, 795 insertions(+), 15 deletions(-) create mode 100644 racevisionGame/src/main/java/mock/model/SplitTODO.java diff --git a/racevisionGame/src/main/java/mock/model/MockRace.java b/racevisionGame/src/main/java/mock/model/MockRace.java index fec34ad7..b9fb32be 100644 --- a/racevisionGame/src/main/java/mock/model/MockRace.java +++ b/racevisionGame/src/main/java/mock/model/MockRace.java @@ -33,14 +33,6 @@ public class MockRace extends Race { */ private List boats; - - - /** - * A copy of the boundary list, except "shrunk" inwards by 50m. - */ - private List shrinkBoundary; - - /** * The scale factor of the race. * See {@link Constants#RaceTimeScale}. @@ -69,8 +61,6 @@ public class MockRace extends Race { this.boats = this.generateMockBoats(boatDataSource.getBoats(), raceDataSource.getParticipants(), polars); - this.shrinkBoundary = GPSCoordinate.getShrinkBoundary(this.boundary); - //Set up wind generator. It may be tidier to create this outside the race (with the values sourced from a data file maybe?) and pass it in. this.windGenerator = new WindGenerator( Bearing.fromDegrees(225), diff --git a/racevisionGame/src/main/java/mock/model/RaceLogic.java b/racevisionGame/src/main/java/mock/model/RaceLogic.java index b8e904a6..0673e226 100644 --- a/racevisionGame/src/main/java/mock/model/RaceLogic.java +++ b/racevisionGame/src/main/java/mock/model/RaceLogic.java @@ -1,4 +1,77 @@ package mock.model; +import network.Messages.Enums.BoatStatusEnum; +import network.Messages.LatestMessages; +import shared.dataInput.BoatDataSource; +import shared.dataInput.RaceDataSource; +import shared.dataInput.RegattaDataSource; +import shared.model.*; + +import java.util.Iterator; +import java.util.List; + public class RaceLogic { + private RaceState raceState; + + /** + * The scale factor of the race. + * See {@link Constants#RaceTimeScale}. + */ + private int scaleFactor; + + /** + * Object used to generate changes in wind speed/direction. + */ + private WindGenerator windGenerator; + + public RaceLogic(BoatDataSource boatDataSource, RaceDataSource raceDataSource, RegattaDataSource regattaDataSource, LatestMessages latestMessages, Polars polars, int timeScale) { + this.raceState = new RaceState(boatDataSource, raceDataSource, regattaDataSource, latestMessages, polars); + this.raceState.run(); + + //Set up wind generator. It may be tidier to create this outside the race (with the values sourced from a data file maybe?) and pass it in. + this.windGenerator = new WindGenerator( + Bearing.fromDegrees(225), + Bearing.fromDegrees(215), + Bearing.fromDegrees(235), + 12d, + 8d, + 16d ); + raceState.setWind(windGenerator.generateBaselineWind()); + } + + private void changeWindDirection() { + Wind nextWind = windGenerator.generateNextWind(raceState.getWind()); + + raceState.setWind(nextWind); + } + + /** + * Returns the number of boats that are still active in the race. + * They become inactive by either finishing or withdrawing. + * @return The number of boats still active in the race. + */ + protected int getNumberOfActiveBoats() { + + int numberOfActiveBoats = 0; + + for (MockBoat boat : raceState.getBoats()) { + + //If the boat is currently racing, count it. + if (boat.getStatus() == BoatStatusEnum.RACING) { + numberOfActiveBoats++; + } + + } + + return numberOfActiveBoats; + } + + /** + * Returns a list of boats in the race. + * @return List of boats in the race. + */ + public List getBoats() { + return raceState.getBoats(); + } + } diff --git a/racevisionGame/src/main/java/mock/model/RaceState.java b/racevisionGame/src/main/java/mock/model/RaceState.java index 4b13cbb4..699417c5 100644 --- a/racevisionGame/src/main/java/mock/model/RaceState.java +++ b/racevisionGame/src/main/java/mock/model/RaceState.java @@ -1,4 +1,158 @@ package mock.model; -public class RaceState { +import network.Messages.Enums.BoatStatusEnum; +import network.Messages.LatestMessages; +import shared.dataInput.BoatDataSource; +import shared.dataInput.RaceDataSource; +import shared.dataInput.RegattaDataSource; +import shared.model.*; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +public class RaceState extends Race { + + /** + * An observable list of boats in the race. + */ + private List boats; + + private Wind wind; + + public RaceState(BoatDataSource boatDataSource, RaceDataSource raceDataSource, RegattaDataSource regattaDataSource, LatestMessages latestMessages, Polars polars) { + super(boatDataSource, raceDataSource, regattaDataSource, latestMessages); + this.boats = this.generateMockBoats(boatDataSource.getBoats(), raceDataSource.getParticipants(), polars); + } + + /** + * Generates a list of MockBoats given a list of Boats, and a list of participating boats. + * @param boats The map of Boats describing boats that are potentially in the race. Maps boat sourceID to boat. + * @param sourceIDs The list of boat sourceIDs describing which specific boats are actually participating. + * @param polars The polars table to be used for boat simulation. + * @return A list of MockBoats that are participating in the race. + */ + private List generateMockBoats(Map boats, List sourceIDs, Polars polars) { + + List mockBoats = new ArrayList<>(sourceIDs.size()); + + //For each sourceID participating... + for (int sourceID : sourceIDs) { + + //Get the boat associated with the sourceID. + Boat boat = boats.get(sourceID); + + //Construct a MockBoat using the Boat and Polars. + MockBoat mockBoat = new MockBoat(boat, polars); + + mockBoats.add(mockBoat); + + } + + return mockBoats; + + } + + /** + * Initialise the boats in the race. + * This sets their starting positions and current legs. + */ + @Override + protected void initialiseBoats() { + + //Gets the starting positions of the boats. + List startingPositions = getSpreadStartingPositions(); + + //Get iterators for our boat and position lists. + Iterator boatIt = this.boats.iterator(); + Iterator startPositionIt = startingPositions.iterator(); + + //Iterate over the pair of lists. + while (boatIt.hasNext() && startPositionIt.hasNext()) { + + //Get the next boat and position. + MockBoat boat = boatIt.next(); + GPSCoordinate startPosition = startPositionIt.next(); + + + //The boat starts on the first leg of the race. + boat.setCurrentLeg(this.legs.get(0)); + + //Boats start with 0 knots speed. + boat.setCurrentSpeed(0d); + + //Place the boat at its starting position. + boat.setCurrentPosition(startPosition); + + //Boats start facing their next marker. + boat.setBearing(boat.calculateBearingToNextMarker()); + + //Sets the boats status to prestart - it changes to racing when the race starts. + boat.setStatus(BoatStatusEnum.PRESTART); + + //We set a large time since tack change so that it calculates a new VMG when the simulation starts. + boat.setTimeSinceTackChange(999999); + + } + + } + + /** + * Creates a list of starting positions for the different boats, so they do not appear cramped at the start line. + * + * @return A list of starting positions. + */ + public List getSpreadStartingPositions() { + + //The first compound marker of the race - the starting gate. + CompoundMark compoundMark = this.legs.get(0).getStartCompoundMark(); + + //The position of the two markers from the compound marker. + GPSCoordinate mark1Position = compoundMark.getMark1Position(); + GPSCoordinate mark2Position = compoundMark.getMark2Position(); + + + //Calculates the azimuth between the two points. + Azimuth azimuth = GPSCoordinate.calculateAzimuth(mark1Position, mark2Position); + + //Calculates the distance between the two points. + double distanceMeters = GPSCoordinate.calculateDistanceMeters(mark1Position, mark2Position); + + //The number of boats in the race. + int numberOfBoats = this.boats.size(); + + //Calculates the distance between each boat. We divide by numberOfBoats + 1 to ensure that no boat is placed on one of the starting gate's marks. + double distanceBetweenBoatsMeters = distanceMeters / (numberOfBoats + 1); + + + //List to store coordinates in. + List positions = new ArrayList<>(); + + //We start spacing boats out from mark 1. + GPSCoordinate position = mark1Position; + + //For each boat, displace position, and store it. + for (int i = 0; i < numberOfBoats; i++) { + + position = GPSCoordinate.calculateNewPosition(position, distanceBetweenBoatsMeters, azimuth); + + positions.add(position); + + } + + return positions; + } + + public void run() { + initialiseBoats(); + } + + public Wind getWind() { + return wind; + } + + public List getBoats() { + return boats; + } } diff --git a/racevisionGame/src/main/java/mock/model/SplitTODO.java b/racevisionGame/src/main/java/mock/model/SplitTODO.java new file mode 100644 index 00000000..20f14973 --- /dev/null +++ b/racevisionGame/src/main/java/mock/model/SplitTODO.java @@ -0,0 +1,555 @@ +//package mock.model; +// +//import javafx.animation.AnimationTimer; +//import network.Messages.BoatLocation; +//import network.Messages.BoatStatus; +//import network.Messages.Enums.BoatStatusEnum; +//import network.Messages.Enums.RaceStatusEnum; +//import network.Messages.LatestMessages; +//import network.Messages.RaceStatus; +//import network.Utils.AC35UnitConverter; +//import shared.dataInput.BoatDataSource; +//import shared.dataInput.RaceDataSource; +//import shared.dataInput.RegattaDataSource; +//import shared.model.*; +// +//import java.time.ZonedDateTime; +//import java.time.temporal.ChronoUnit; +//import java.util.ArrayList; +//import java.util.Iterator; +//import java.util.List; +//import java.util.Map; +// +//import static java.lang.Math.cos; +// +///** +// * Unused class, copy of MockRace so methods can be deleted once they are moved (more of a checklist) +// */ +//public class SplitTODO { +// +// +// /** +// * Represents a yacht race. +// * Has a course, boats, boundaries, etc... +// * Is responsible for simulating the race, and sending messages to a MockOutput instance. +// */ +// public class MockRace extends Race { +// +// /** +// * Constructs a race object with a given RaceDataSource, BoatDataSource, and RegattaDataSource and sends events to the given mockOutput. +// * @param boatDataSource Data source for boat related data (yachts and marker boats). +// * @param raceDataSource Data source for race related data (participating boats, legs, etc...). +// * @param regattaDataSource Data source for race related data (course name, location, timezone, etc...). +// * @param latestMessages The LatestMessages to send events to. +// * @param polars The polars table to be used for boat simulation. +// * @param timeScale The timeScale for the race. See {@link Constants#RaceTimeScale}. +// */ +// public MockRace(BoatDataSource boatDataSource, RaceDataSource raceDataSource, RegattaDataSource regattaDataSource, LatestMessages latestMessages, Polars polars, int timeScale) { +// +// super(boatDataSource, raceDataSource, regattaDataSource, latestMessages); +// +// this.scaleFactor = timeScale; +// } +// +// +// +// /** +// * Parse the compound marker boats through mock output. +// */ +// private void parseMarks() { +// for (CompoundMark compoundMark : this.compoundMarks) { +// +// //Get the individual marks from the compound mark. +// Mark mark1 = compoundMark.getMark1(); +// Mark mark2 = compoundMark.getMark2(); +// +// //If they aren't null, parse them (some compound marks only have one mark). +// if (mark1 != null) { +// this.parseIndividualMark(mark1); +// } +// +// if (mark2 != null) { +// this.parseIndividualMark(mark2); +// } +// +// } +// } +// +// /** +// * Parses an individual marker boat, and sends it to mockOutput. +// * @param mark The marker boat to parse. +// */ +// private void parseIndividualMark(Mark mark) { +// +// //Create message. +// BoatLocation boatLocation = new BoatLocation( +// mark.getSourceID(), +// mark.getPosition().getLatitude(), +// mark.getPosition().getLongitude(), +// this.boatLocationSequenceNumber, +// 0, 0, +// this.raceClock.getCurrentTimeMilli()); +// +// //Iterates the sequence number. +// this.boatLocationSequenceNumber++; +// +// this.latestMessages.setBoatLocation(boatLocation); +// +// +// } +// +// /** +// * Parse the boats in the race, and send it to mockOutput. +// */ +// private void parseBoatLocations() { +// +// //Parse each boat. +// for (MockBoat boat : this.boats) { +// +// this.parseIndividualBoatLocation(boat); +// +// } +// +// } +// +// /** +// * Parses an individual boat, and sends it to mockOutput. +// * @param boat The boat to parse. +// */ +// private void parseIndividualBoatLocation(MockBoat boat) { +// +// BoatLocation boatLocation = new BoatLocation( +// boat.getSourceID(), +// boat.getCurrentPosition().getLatitude(), +// boat.getCurrentPosition().getLongitude(), +// this.boatLocationSequenceNumber, +// boat.getBearing().degrees(), +// boat.getCurrentSpeed(), +// this.raceClock.getCurrentTimeMilli()); +// +// //Iterates the sequence number. +// this.boatLocationSequenceNumber++; +// +// this.latestMessages.setBoatLocation(boatLocation); +// +// } +// +// +// /** +// * Updates the race time to a specified value, in milliseconds since the unix epoch. +// * @param currentTime Milliseconds since unix epoch. +// */ +// private void updateRaceTime(long currentTime) { +// this.raceClock.setUTCTime(currentTime); +// } +// +// +// /** +// * Updates the race status enumeration based on the current time. +// */ +// private void updateRaceStatusEnum() { +// +// //The millisecond duration of the race. Negative means it hasn't started, so we flip sign. +// long timeToStart = - this.raceClock.getDurationMilli(); +// +// +// if (timeToStart > Constants.RacePreStartTime) { +// //Time > 3 minutes is the prestart period. +// this.setRaceStatusEnum(RaceStatusEnum.PRESTART); +// +// } else if ((timeToStart <= Constants.RacePreStartTime) && (timeToStart >= Constants.RacePreparatoryTime)) { +// //Time between [1, 3] minutes is the warning period. +// this.setRaceStatusEnum(RaceStatusEnum.WARNING); +// +// } else if ((timeToStart <= Constants.RacePreparatoryTime) && (timeToStart > 0)) { +// //Time between (0, 1] minutes is the preparatory period. +// this.setRaceStatusEnum(RaceStatusEnum.PREPARATORY); +// +// } else { +// //Otherwise, the race has started! +// this.setRaceStatusEnum(RaceStatusEnum.STARTED); +// +// } +// +// +// } +// +// /** +// * Parses the race status, and sends it to mockOutput. +// */ +// private void parseRaceStatus() { +// +// //A race status message contains a list of boat statuses. +// List boatStatuses = new ArrayList<>(); +// +// //Add each boat status to the status list. +// for (MockBoat boat : this.boats) { +// +// BoatStatus boatStatus = new BoatStatus( +// boat.getSourceID(), +// boat.getStatus(), +// boat.getCurrentLeg().getLegNumber(), +// boat.getEstimatedTimeAtNextMark().toInstant().toEpochMilli() ); +// +// boatStatuses.add(boatStatus); +// } +// +// +// //Convert wind direction and speed to ints. //TODO this conversion should be done inside the racestatus class. +// int windDirectionInt = AC35UnitConverter.encodeHeading(this.getWindDirection().degrees()); +// int windSpeedInt = (int) (this.getWindSpeed() * Constants.KnotsToMMPerSecond); +// +// //Create race status object, and send it. +// RaceStatus raceStatus = new RaceStatus( +// System.currentTimeMillis(), +// this.raceId, +// this.getRaceStatusEnum().getValue(), +// this.raceClock.getStartingTimeMilli(), +// windDirectionInt, +// windSpeedInt, +// this.getRaceType().getValue(), +// boatStatuses); +// +// +// this.latestMessages.setRaceStatus(raceStatus); +// +// +// } +// +// +// /** +// * Sets the status of all boats in the race to RACING. +// */ +// private void setBoatsStatusToRacing() { +// +// for (MockBoat boat : this.boats) { +// boat.setStatus(BoatStatusEnum.RACING); +// } +// } +// +// +// /** +// * Sets the estimated time at next mark for each boat to a specified time. This is used during the countdown timer to provide this value to boat before the race starts. +// * @param time The time to provide to each boat. +// */ +// private void setBoatsTimeNextMark(ZonedDateTime time) { +// +// for (MockBoat boat : this.boats) { +// boat.setEstimatedTimeAtNextMark(time); +// } +// } +// +// +// /** +// * Countdown timer until race starts. +// */ +// protected AnimationTimer countdownTimer = new AnimationTimer() { +// +// +// long currentTime = System.currentTimeMillis(); +// +// @Override +// public void handle(long arg0) { +// +// //Update race time. +// updateRaceTime(currentTime); +// +// //Update the race status based on the current time. +// updateRaceStatusEnum(); +// +// //Provide boat's with an estimated time at next mark until the race starts. +// setBoatsTimeNextMark(raceClock.getCurrentTime()); +// +// //Parse the boat locations. +// parseBoatLocations(); +// +// //Parse the marks. +// parseMarks(); +// +// // Change wind direction +// changeWindDirection(); +// +// //Parse the race status. +// parseRaceStatus(); +// +// +// if (getRaceStatusEnum() == RaceStatusEnum.STARTED) { +// setBoatsStatusToRacing(); +// raceTimer.start(); +// this.stop(); +// } +// +// //Update the animations timer's time. +// currentTime = System.currentTimeMillis(); +// } +// }; +// +// +// /** +// * Timer that runs for the duration of the race, until all boats finish. +// */ +// private AnimationTimer raceTimer = new AnimationTimer() { +// +// /** +// * Start time of loop, in milliseconds. +// */ +// long timeRaceStarted = System.currentTimeMillis(); +// +// /** +// * Current time during a loop iteration. +// */ +// long currentTime = System.currentTimeMillis(); +// +// /** +// * The time of the previous frame, in milliseconds. +// */ +// long lastFrameTime = timeRaceStarted; +// +// @Override +// public void handle(long arg0) { +// +// //Get the current time. +// currentTime = System.currentTimeMillis(); +// +// //Update race time. +// updateRaceTime(currentTime); +// +// +// //As long as there is at least one boat racing, we still simulate the race. +// if (getNumberOfActiveBoats() != 0) { +// +// //Get the time period of this frame. +// long framePeriod = currentTime - lastFrameTime; +// +// //For each boat, we update its position, and generate a BoatLocationMessage. +// for (MockBoat boat : boats) { +// +// //If it is still racing, update its position. +// if (boat.getStatus() == BoatStatusEnum.RACING) { +// +// updatePosition(boat, framePeriod, raceClock.getDurationMilli()); +// +// } +// +// } +// +// } else { +// //Otherwise, the race is over! +// raceFinished.start(); +// setRaceStatusEnum(RaceStatusEnum.FINISHED); +// this.stop(); +// } +// +// if (getNumberOfActiveBoats() != 0) { +// // Change wind direction +// changeWindDirection(); +// +// //Parse the boat locations. +// parseBoatLocations(); +// +// //Parse the marks. +// parseMarks(); +// +// //Parse the race status. +// parseRaceStatus(); +// +// +// //Update the last frame time. +// this.lastFrameTime = currentTime; +// } +// } +// }; +// +// /** +// * Broadcast that the race has finished. +// */ +// protected AnimationTimer raceFinished = new AnimationTimer(){ +// int iters = 0; +// @Override +// public void handle(long now) { +// +// parseRaceStatus(); +// +// if (iters > 500) { +// stop(); +// } +// iters++; +// } +// }; +// +// +// /** +// * Calculates a boat's VMG. +// * @param boat The boat to calculate VMG for. +// * @return VMG for the specified boat. +// */ +// private VMG calculateVMG(MockBoat boat) { +// +// +// //Find the VMG inside these bounds. +// VMG bestVMG = boat.getPolars().calculateVMG(this.getWindDirection(), this.getWindSpeed(), boat.calculateBearingToNextMarker(), Bearing.fromDegrees(0d), Bearing.fromDegrees(359.99999d)); +// +// +// return bestVMG; +// +// } +// +// +// /** +// * Determines whether or not a given VMG improves the velocity of a boat, if it were currently using currentVMG. +// * @param currentVMG The current VMG of the boat. +// * @param potentialVMG The new VMG to test. +// * @param bearingToDestination The bearing between the boat and its destination. +// * @return True if the new VMG is improves velocity, false otherwise. +// */ +// private boolean improvesVelocity(VMG currentVMG, VMG potentialVMG, Bearing bearingToDestination) { +// +// //Calculates the angle between the boat and its destination. +// Angle angleBetweenDestAndHeading = Angle.fromDegrees(currentVMG.getBearing().degrees() - bearingToDestination.degrees()); +// +// //Calculates the angle between the new VMG and the boat's destination. +// Angle angleBetweenDestAndNewVMG = Angle.fromDegrees(potentialVMG.getBearing().degrees() - bearingToDestination.degrees()); +// +// +// //Calculate the boat's current velocity. +// double currentVelocity = Math.cos(angleBetweenDestAndHeading.radians()) * currentVMG.getSpeed(); +// +// //Calculate the potential velocity with the new VMG. +// double vmgVelocity = Math.cos(angleBetweenDestAndNewVMG.radians()) * potentialVMG.getSpeed(); +// +// //Return whether or not the new VMG gives better velocity. +// return vmgVelocity > currentVelocity; +// +// } +// +// /** +// * Determines whether or not a given VMG improves the velocity of a boat. +// * @param boat The boat to test. +// * @param vmg The new VMG to test. +// * @return True if the new VMG is improves velocity, false otherwise. +// */ +// private boolean improvesVelocity(MockBoat boat, VMG vmg) { +// +// //Get the boats "current" VMG. +// VMG boatVMG = new VMG(boat.getCurrentSpeed(), boat.getBearing()); +// +// //Check if the new VMG is better than the boat's current VMG. +// return this.improvesVelocity(boatVMG, vmg, boat.calculateBearingToNextMarker()); +// +// } +// +// +// /** +// * Calculates the distance a boat has travelled and updates its current position according to this value. +// * +// * @param boat The boat to be updated. +// * @param updatePeriodMilliseconds The time, in milliseconds, since the last update. +// * @param totalElapsedMilliseconds The total number of milliseconds that have elapsed since the start of the race. +// */ +// protected void updatePosition(MockBoat boat, long updatePeriodMilliseconds, long totalElapsedMilliseconds) { +// +// //Checks if the current boat has finished the race or not. +// boolean finish = this.isLastLeg(boat.getCurrentLeg()); +// +// if (!finish) { +// +// +// //Calculates the distance travelled, in meters, in the current timeslice. +// double distanceTravelledMeters = boat.calculateMetersTravelled(updatePeriodMilliseconds); +// +// //Scale it. +// distanceTravelledMeters = distanceTravelledMeters * this.scaleFactor; +// +// +// //Move the boat forwards that many meters, and advances its time counters by enough milliseconds. +// boat.moveForwards(distanceTravelledMeters, updatePeriodMilliseconds * this.scaleFactor); +// +// long tackPeriod = 15000; +// if (boat.getTimeSinceTackChange() > tackPeriod) { +// //Calculate the new VMG. +// VMG newVMG = this.calculateVMG(boat); +// +// +// //If the new vmg improves velocity, use it. +// if (improvesVelocity(boat, newVMG)) { +// boat.setVMG(newVMG); +// +// } +// } +// +// this.updateEstimatedTime(boat); +// +// +// //Check the boats position (update leg and stuff). +// this.checkPosition(boat, totalElapsedMilliseconds); +// +// } +// +// } +// +// +// /** +// * Checks if a boat has finished any legs, or has pulled out of race (DNF). +// * @param boat The boat to check. +// * @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 = 100.0 / Constants.NMToMetersConversion; //100 meters. TODO should be more like 5-10. +// +// if (boat.calculateDistanceToNextMarker() < epsilonNauticalMiles) { +// //Boat has reached its target marker, and has moved on to a new leg. +// +// +// +// //Calculate how much the boat overshot the marker by. +// double overshootMeters = boat.calculateDistanceToNextMarker(); +// +// +// //Move boat on to next leg. +// Leg nextLeg = this.legs.get(boat.getCurrentLeg().getLegNumber() + 1); +// boat.setCurrentLeg(nextLeg); +// +// //Add overshoot distance into the distance travelled for the next leg. +// boat.setDistanceTravelledInLeg(overshootMeters); +// +// //Setting a high value for this allows the boat to immediately do a large turn, as it needs to in order to get to the next mark. +// boat.setTimeSinceTackChange(999999); +// +// +// //Check if the boat has finished or stopped racing. +// +// if (this.isLastLeg(boat.getCurrentLeg())) { +// //Boat has finished. +// boat.setTimeFinished(timeElapsed); +// boat.setCurrentSpeed(0); +// boat.setStatus(BoatStatusEnum.FINISHED); +// +// } +// +// } +// +// } +// +// /** +// * Updates the boat's estimated time to next mark if positive +// * @param boat to estimate time given its velocity +// */ +// private void updateEstimatedTime(MockBoat boat) { +// +// double velocityToMark = boat.getCurrentSpeed() * cos(boat.getBearing().radians() - boat.calculateBearingToNextMarker().radians()) / Constants.KnotsToMMPerSecond; +// +// if (velocityToMark > 0) { +// +// //Calculate milliseconds until boat reaches mark. +// long timeFromNow = (long) (1000 * boat.calculateDistanceToNextMarker() / velocityToMark); +// +// //Calculate time at which it will reach mark. +// ZonedDateTime timeAtMark = this.raceClock.getCurrentTime().plus(timeFromNow, ChronoUnit.MILLIS); +// boat.setEstimatedTimeAtNextMark(timeAtMark); +// } +// +// } +// } +//} diff --git a/racevisionGame/src/main/java/shared/model/Race.java b/racevisionGame/src/main/java/shared/model/Race.java index aec57882..3235f60f 100644 --- a/racevisionGame/src/main/java/shared/model/Race.java +++ b/racevisionGame/src/main/java/shared/model/Race.java @@ -226,7 +226,7 @@ public abstract class Race implements Runnable { * Sets the current race status. * @param raceStatusEnum The new status of the race. */ - protected void setRaceStatusEnum(RaceStatusEnum raceStatusEnum) { + public void setRaceStatusEnum(RaceStatusEnum raceStatusEnum) { this.raceStatusEnum = raceStatusEnum; } @@ -253,7 +253,7 @@ public abstract class Race implements Runnable { * @param windBearing New wind bearing. * @param windSpeedKnots New wind speed, in knots. */ - protected void setWind(Bearing windBearing, double windSpeedKnots) { + public void setWind(Bearing windBearing, double windSpeedKnots) { Wind wind = new Wind(windBearing, windSpeedKnots); setWind(wind); } @@ -262,7 +262,7 @@ public abstract class Race implements Runnable { * Updates the race to have a specified wind (bearing and speed). * @param wind New wind. */ - protected void setWind(Wind wind) { + public void setWind(Wind wind) { this.raceWind.setValue(wind); } diff --git a/racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java b/racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java index fb6a257b..dc3f3a03 100644 --- a/racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java +++ b/racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java @@ -9,6 +9,7 @@ import visualiser.gameController.Keys.KeyFactory; import java.io.DataInputStream; import java.io.IOException; import java.net.Socket; +import java.util.Queue; /** * Service for dispatching key press data to race from client @@ -23,6 +24,9 @@ public class ControllerServer implements Runnable { */ private DataInputStream inputStream; + // Last boat action received + private Queue boatActions; + /** * Initialise server-side controller with live client socket * @param socket to client @@ -49,11 +53,15 @@ public class ControllerServer implements Runnable { BinaryMessageDecoder encodedMessage = new BinaryMessageDecoder(message); BoatActionDecoder boatActionDecoder = new BoatActionDecoder(encodedMessage.getMessageBody()); BoatActionEnum decodedMessage = boatActionDecoder.getBoatAction(); - System.out.println("Received key: " + decodedMessage); + boatActions.add(decodedMessage); } } catch (IOException e) { e.printStackTrace(); } } } + + public BoatActionEnum getNextBoatAction() { + return boatActions.remove(); + } } From 14ce5fcaffbf773d66719ab3640ca5dfd006dcaf Mon Sep 17 00:00:00 2001 From: zwu18 Date: Fri, 4 Aug 2017 03:56:55 +1200 Subject: [PATCH 2/7] Made changes to TackGybeCommand and VMGCommand classes to fit pattern layout. #Story[1097] --- .../src/main/java/mock/model/MockRace.java | 4 ++-- .../model/commandFactory/CommandFactory.java | 2 +- .../model/commandFactory/TackGybeCommand.java | 11 ++++++++++- .../mock/model/commandFactory/VMGCommand.java | 17 +++++++++-------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/racevisionGame/src/main/java/mock/model/MockRace.java b/racevisionGame/src/main/java/mock/model/MockRace.java index bfcf5efc..81042828 100644 --- a/racevisionGame/src/main/java/mock/model/MockRace.java +++ b/racevisionGame/src/main/java/mock/model/MockRace.java @@ -261,7 +261,6 @@ public class MockRace extends Race { //For each boat, we update its position, and generate a BoatLocationMessage. for (MockBoat boat : boats) { - //If it is still racing, update its position. if (boat.getStatus() == BoatStatusEnum.RACING) { @@ -417,6 +416,7 @@ public class MockRace extends Race { */ public boolean improvesVelocity(VMG currentVMG, VMG potentialVMG, Bearing bearingToDestination) { + //Calculates the angle between the boat and its destination. Angle angleBetweenDestAndHeading = Angle.fromDegrees(currentVMG.getBearing().degrees() - bearingToDestination.degrees()); @@ -478,7 +478,7 @@ public class MockRace extends Race { boat.moveForwards(distanceTravelledMeters); - long tackPeriod = 15000; + long tackPeriod = 1000; if (boat.getTimeSinceTackChange() > tackPeriod) { //Calculate the new VMG. diff --git a/racevisionGame/src/main/java/mock/model/commandFactory/CommandFactory.java b/racevisionGame/src/main/java/mock/model/commandFactory/CommandFactory.java index ace2f3be..8a53547c 100644 --- a/racevisionGame/src/main/java/mock/model/commandFactory/CommandFactory.java +++ b/racevisionGame/src/main/java/mock/model/commandFactory/CommandFactory.java @@ -5,5 +5,5 @@ import mock.model.MockRace; public interface CommandFactory { - void runCommand(MockBoat boat, MockRace race); + void execute(); } diff --git a/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java b/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java index ef776536..3a7dc0eb 100644 --- a/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java +++ b/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java @@ -11,8 +11,15 @@ import shared.model.Bearing; public class TackGybeCommand implements CommandFactory { //The refactoring of MockRace will require changes to be made + + private MockBoat boat; + + public TackGybeCommand(final MockBoat boat){ + this.boat = boat; + } + @Override - public void runCommand(MockBoat boat, MockRace race) { + public void execute() { /*VMG newVMG = boat.getPolars().calculateVMG( race.getWindDirection(), race.getWindSpeed(), @@ -23,5 +30,7 @@ public class TackGybeCommand implements CommandFactory { if(race.improvesVelocity(boatVMG, newVMG, boat.calculateBearingToNextMarker())){ boat.setVMG(newVMG); }*/ + Bearing newBearing = Bearing.fromDegrees(360d - boat.getBearing().degrees()); + boat.setBearing(newBearing); } } diff --git a/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java b/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java index 5d11a27b..a28cfa57 100644 --- a/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java +++ b/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java @@ -10,15 +10,16 @@ import shared.model.Bearing; */ public class VMGCommand implements CommandFactory { + private MockBoat boat; + + public VMGCommand(final MockBoat boat){ + this.boat = boat; + } + + //The refactoring of MockRace will require changes to be made @Override - public void runCommand(MockBoat boat, MockRace race) { - /*VMG newVMG = boat.getPolars().calculateVMG( - race.getWindDirection(), - race.getWindSpeed(), - boat.calculateBearingToNextMarker(), - Bearing.fromDegrees(0d), - Bearing.fromDegrees(359.99999d)); - boat.setVMG(newVMG);*/ + public void execute() { + //MOCKBOAT SHOULD HAVE PARAMETER TO TOGGLE AUTO-VMG ON AND OFF } } From 074e2e590bcbfa968dfed5a306967fb2b4d5d3ea Mon Sep 17 00:00:00 2001 From: zwu18 Date: Sun, 6 Aug 2017 14:48:46 +1200 Subject: [PATCH 3/7] VMGCommand now toggles autoVMG on and off. Linked up observer and observable so the current boat can now be controlled. #Story[1097] --- .../src/main/java/mock/app/ConnectionAcceptor.java | 13 ++++++++++++- racevisionGame/src/main/java/mock/app/Event.java | 5 +++++ .../src/main/java/mock/model/MockBoat.java | 4 ++++ .../mock/model/commandFactory/TackGybeCommand.java | 2 ++ .../java/mock/model/commandFactory/VMGCommand.java | 7 +++++++ .../visualiser/gameController/ControllerServer.java | 9 ++++++++- 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/racevisionGame/src/main/java/mock/app/ConnectionAcceptor.java b/racevisionGame/src/main/java/mock/app/ConnectionAcceptor.java index 97a974a9..37ed83ed 100644 --- a/racevisionGame/src/main/java/mock/app/ConnectionAcceptor.java +++ b/racevisionGame/src/main/java/mock/app/ConnectionAcceptor.java @@ -1,5 +1,6 @@ package mock.app; +import mock.model.RaceLogic; import network.Messages.Enums.XMLMessageType; import network.Messages.LatestMessages; import network.Messages.XMLMessage; @@ -43,6 +44,10 @@ public class ConnectionAcceptor implements Runnable { private short boatXMLSequenceNumber; //regatta xml sequence number private short regattaXMLSequenceNumber; + //controller server + private ControllerServer controllerServer; + // + private RaceLogic rl = null; /** * Connection Acceptor Constructor @@ -65,6 +70,11 @@ public class ConnectionAcceptor implements Runnable { return serverPort; } + + public void setRace(RaceLogic rl){ + this.rl = rl; + } + /** * Run the Acceptor */ @@ -76,9 +86,10 @@ public class ConnectionAcceptor implements Runnable { Socket mockSocket = serverSocket.accept(); DataOutputStream outToVisualiser = new DataOutputStream(mockSocket.getOutputStream()); MockOutput mockOutput = new MockOutput(latestMessages, outToVisualiser); - ControllerServer controllerServer = new ControllerServer(mockSocket); + this.controllerServer = new ControllerServer(mockSocket, rl); new Thread(mockOutput).start(); new Thread(controllerServer).start(); + System.out.println("I'm in connectionAcceptor"); mockOutputList.add(mockOutput); System.out.println(String.format("%d number of Visualisers Connected.", mockOutputList.size())); } catch (IOException e) { diff --git a/racevisionGame/src/main/java/mock/app/Event.java b/racevisionGame/src/main/java/mock/app/Event.java index b4b0586c..15113159 100644 --- a/racevisionGame/src/main/java/mock/app/Event.java +++ b/racevisionGame/src/main/java/mock/app/Event.java @@ -82,6 +82,7 @@ public class Event { * @throws InvalidRegattaDataException Thrown if the regatta xml file cannot be parsed. */ public void start() throws InvalidRaceDataException, XMLReaderException, InvalidBoatDataException, InvalidRegattaDataException { + new Thread(mockOutput).start(); sendXMLs(); @@ -94,7 +95,11 @@ public class Event { //Create and start race. RaceLogic newRace = new RaceLogic(new MockRace(boatDataSource, raceDataSource, regattaDataSource, this.latestMessages, this.boatPolars, Constants.RaceTimeScale), this.latestMessages); + mockOutput.setRace(newRace); + new Thread(newRace).start(); + + System.out.println("I'm in event"); } /** diff --git a/racevisionGame/src/main/java/mock/model/MockBoat.java b/racevisionGame/src/main/java/mock/model/MockBoat.java index 104fa264..2ed15b6c 100644 --- a/racevisionGame/src/main/java/mock/model/MockBoat.java +++ b/racevisionGame/src/main/java/mock/model/MockBoat.java @@ -203,4 +203,8 @@ public class MockBoat extends Boat { public void setAutoVMG(boolean autoVMG) { this.autoVMG = autoVMG; } + + public boolean getAutoVMG(){ + return autoVMG; + } } diff --git a/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java b/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java index 150a1da8..11acfa0a 100644 --- a/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java +++ b/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java @@ -2,6 +2,7 @@ package mock.model.commandFactory; import mock.model.MockBoat; import mock.model.MockRace; +import shared.model.Bearing; /** * Created by David on 2/08/2017. @@ -28,5 +29,6 @@ public class TackGybeCommand implements Command { if(race.improvesVelocity(boatVMG, newVMG, boat.calculateBearingToNextMarker())){ boat.setVMG(newVMG); }*/ + this.boat.setBearing(Bearing.fromDegrees(360 - boat.getBearing().degrees())); } } diff --git a/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java b/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java index 64cc6a9f..9cd558a5 100644 --- a/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java +++ b/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java @@ -25,5 +25,12 @@ public class VMGCommand implements Command { Bearing.fromDegrees(0d), Bearing.fromDegrees(359.99999d)); boat.setVMG(newVMG);*/ + if (boat.getAutoVMG()){ + boat.setAutoVMG(false); + System.out.println("Auto VMG off!"); + } else { + boat.setAutoVMG(true); + System.out.println("Auto VMG on!"); + } } } diff --git a/racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java b/racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java index a2f8c80e..af2efec9 100644 --- a/racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java +++ b/racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java @@ -1,5 +1,6 @@ package visualiser.gameController; +import mock.model.RaceLogic; import mock.model.commandFactory.Command; import mock.model.commandFactory.CommandFactory; import network.BinaryMessageDecoder; @@ -29,13 +30,19 @@ public class ControllerServer extends Observable implements Runnable { * Last received boat action */ private BoatActionEnum action; + /** + * + */ + private RaceLogic rc; /** * Initialise server-side controller with live client socket * @param socket to client */ - public ControllerServer(Socket socket) { + public ControllerServer(Socket socket, RaceLogic rc) { this.socket = socket; + this.rc = rc; + this.addObserver(rc); try { this.inputStream = new DataInputStream(this.socket.getInputStream()); } catch (IOException e) { From 18f14c7542e258b466b8b624c5dda72f3293358e Mon Sep 17 00:00:00 2001 From: zwu18 Date: Sun, 6 Aug 2017 16:12:53 +1200 Subject: [PATCH 4/7] VMGCommand now toggles autoVMG on and off. Linked up observer and observable so the current boat can now be controlled. Fixed autoVMG not working. #Story[1097] --- .../src/main/java/mock/model/MockRace.java | 2 +- .../model/commandFactory/TackGybeCommand.java | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/racevisionGame/src/main/java/mock/model/MockRace.java b/racevisionGame/src/main/java/mock/model/MockRace.java index 0ae5cfcc..7cb91ebc 100644 --- a/racevisionGame/src/main/java/mock/model/MockRace.java +++ b/racevisionGame/src/main/java/mock/model/MockRace.java @@ -350,7 +350,7 @@ public class MockRace extends Race { } private void newOptimalVMG(MockBoat boat) { - long tackPeriod = 15000; + long tackPeriod = 1000; if (boat.getTimeSinceTackChange() > tackPeriod) { //Calculate the new VMG. diff --git a/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java b/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java index 11acfa0a..ff04c54e 100644 --- a/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java +++ b/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java @@ -2,6 +2,7 @@ package mock.model.commandFactory; import mock.model.MockBoat; import mock.model.MockRace; +import mock.model.VMG; import shared.model.Bearing; /** @@ -19,16 +20,14 @@ public class TackGybeCommand implements Command { //The refactoring of MockRace will require changes to be made @Override public void execute() { - /*VMG newVMG = boat.getPolars().calculateVMG( - race.getWindDirection(), - race.getWindSpeed(), - boat.calculateBearingToNextMarker(), - Bearing.fromDegrees(0d), - Bearing.fromDegrees(359.99999d)); - VMG boatVMG = new VMG(boat.getCurrentSpeed(), boat.getBearing()); - if(race.improvesVelocity(boatVMG, newVMG, boat.calculateBearingToNextMarker())){ - boat.setVMG(newVMG); + /*if(boat.getBearing().degrees()>180){ + boat.setBearing(Bearing.fromDegrees(360 - race.getWindDirection().degrees())); + } else { + boat.setBearing(Bearing.fromDegrees(race.getWindDirection().degrees())); }*/ - this.boat.setBearing(Bearing.fromDegrees(360 - boat.getBearing().degrees())); + System.out.println(race.getWindDirection().degrees()); + double angle = Math.max(race.getWindDirection().degrees(), boat.getBearing().degrees()) - Math.min(race.getWindDirection().degrees(), boat.getBearing().degrees()); + boat.setBearing(Bearing.fromDegrees(angle)); } } + From a38898982764d19815b981b0e1879d50f05fb706 Mon Sep 17 00:00:00 2001 From: zwu18 Date: Sun, 6 Aug 2017 16:38:44 +1200 Subject: [PATCH 5/7] Reworked TackGybeCommand. Current boat in race will now tack and gybe when control is pressed. #Story[1097] --- .../model/commandFactory/TackGybeCommand.java | 22 ++++++++++++++++--- .../mock/model/commandFactory/VMGCommand.java | 7 ------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java b/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java index ff04c54e..f964a17e 100644 --- a/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java +++ b/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java @@ -25,9 +25,25 @@ public class TackGybeCommand implements Command { } else { boat.setBearing(Bearing.fromDegrees(race.getWindDirection().degrees())); }*/ - System.out.println(race.getWindDirection().degrees()); - double angle = Math.max(race.getWindDirection().degrees(), boat.getBearing().degrees()) - Math.min(race.getWindDirection().degrees(), boat.getBearing().degrees()); - boat.setBearing(Bearing.fromDegrees(angle)); + /*double angle = Math.max(race.getWindDirection().degrees(), boat.getBearing().degrees()) - Math.min(race.getWindDirection().degrees(), boat.getBearing().degrees()); + boat.setBearing(Bearing.fromDegrees(angle));*/ + double boatAngle = boat.getBearing().degrees(); + double windAngle =race.getWindDirection().degrees(); + double differenceAngle = calcDistance(boatAngle, windAngle); + double angleA = windAngle + differenceAngle; + double angleB = windAngle - differenceAngle; + if(angleA % 360 == boatAngle){ + boat.setBearing(Bearing.fromDegrees(angleB)); + } else { + boat.setBearing(Bearing.fromDegrees(angleA)); + } + } + + private double calcDistance(double degreeA, double degreeB){ + double phi = Math.abs(degreeB - degreeA) % 360; + double distance = phi > 180 ? 360 - phi : phi; + return distance; } + } diff --git a/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java b/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java index 9cd558a5..d6e3d988 100644 --- a/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java +++ b/racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java @@ -18,13 +18,6 @@ public class VMGCommand implements Command { //The refactoring of MockRace will require changes to be made @Override public void execute() { - /*VMG newVMG = boat.getPolars().calculateVMG( - race.getWindDirection(), - race.getWindSpeed(), - boat.calculateBearingToNextMarker(), - Bearing.fromDegrees(0d), - Bearing.fromDegrees(359.99999d)); - boat.setVMG(newVMG);*/ if (boat.getAutoVMG()){ boat.setAutoVMG(false); System.out.println("Auto VMG off!"); From ddaa2623ca3eb2a11ae4d2709b231cbf2e7cd710 Mon Sep 17 00:00:00 2001 From: zwu18 Date: Mon, 7 Aug 2017 02:56:24 +1200 Subject: [PATCH 6/7] Added tests for TackGybeCommand class. #Story[1097] --- .../model/commandFactory/TackGybeCommand.java | 2 +- .../commandFactory/TackGybeCommandTest.java | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 racevisionGame/src/test/java/mock/model/commandFactory/TackGybeCommandTest.java diff --git a/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java b/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java index f964a17e..447ab2fb 100644 --- a/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java +++ b/racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java @@ -39,7 +39,7 @@ public class TackGybeCommand implements Command { } } - private double calcDistance(double degreeA, double degreeB){ + public double calcDistance(double degreeA, double degreeB){ double phi = Math.abs(degreeB - degreeA) % 360; double distance = phi > 180 ? 360 - phi : phi; return distance; diff --git a/racevisionGame/src/test/java/mock/model/commandFactory/TackGybeCommandTest.java b/racevisionGame/src/test/java/mock/model/commandFactory/TackGybeCommandTest.java new file mode 100644 index 00000000..7ac71956 --- /dev/null +++ b/racevisionGame/src/test/java/mock/model/commandFactory/TackGybeCommandTest.java @@ -0,0 +1,42 @@ +package mock.model.commandFactory; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by David on 7/08/2017. + */ +public class TackGybeCommandTest { + + private double degreeA; + private double degreeB; + private double degreeC; + private double degreeD; + TackGybeCommand tgc; + + //Run before tests + @Before + public void setUp(){ + degreeA = 150.0; + degreeB = 300.0; + degreeC = 10.0; + degreeD = 350.0; + tgc = new TackGybeCommand(null, null); + } + + //Test when degree difference is <180 + @Test + public void angleDistanceCalculationLow(){ + double result = tgc.calcDistance(degreeA, degreeB); + assertEquals(150.0, result, 0); + } + + //Test when degree difference is >180 + @Test + public void angleDistanceCalculationHigh(){ + double result = tgc.calcDistance(degreeC, degreeD); + assertEquals(20.0, result, 0); + } +} From 0bf2c6106b21833485d9a2ef4521add1754f18b5 Mon Sep 17 00:00:00 2001 From: Joseph Gardner Date: Mon, 7 Aug 2017 12:03:34 +1200 Subject: [PATCH 7/7] Boat updating speed after key press has been fixed. #fix #story[1094] --- racevisionGame/src/main/java/mock/model/MockRace.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/racevisionGame/src/main/java/mock/model/MockRace.java b/racevisionGame/src/main/java/mock/model/MockRace.java index 7cb91ebc..3ac8418e 100644 --- a/racevisionGame/src/main/java/mock/model/MockRace.java +++ b/racevisionGame/src/main/java/mock/model/MockRace.java @@ -374,8 +374,8 @@ public class MockRace extends Race { this.getWindDirection(), this.getWindSpeed(), boat.getBearing(), - boat.getBearing(), - boat.getBearing()); + Bearing.fromDegrees(boat.getBearing().degrees() - 1), + Bearing.fromDegrees(boat.getBearing().degrees() + 1)); if (vmg.getSpeed() > 0) { boat.setCurrentSpeed(vmg.getSpeed()); }