Also got client-server handshake working. Multiple clients can connect and control their own boat. The client's boat has a larger black triangle drawn around it. Probably needs tidying up. Added isClientBoat boolean to VisualiserBoat. WindGenerator is now an interface, implemented by ConstantWindGenerator (useful for testing) and RandomWindGenerator. Added ConstantWindGeneratorTest. RandomWindGenerator was formerly WindGenerator. The WindGenerator is passed in to MockRace. CommandFactory throws a CommandConstructionException if it cannot create a command. MessageSerialiser and MessageDeserialiser correctly terminate on error. Readded VisualiserInput's switch statement in the main loop, pending a refactor. Removed the sleep statement from LobbyController - it was blocking javaFX thread. Lobby.fxml: moved buttons and text input into grid panes, so they don't break when you resize screen. Added some test object creation functions in several test classes (MockRaceTest.createMockRace(), BoatXMLReaderTest.createBoatDataSource(), etc...). #story[1095]main
commit
19984772c0
@ -0,0 +1,24 @@
|
||||
package mock.exceptions;
|
||||
|
||||
/**
|
||||
* An exception thrown when we cannot create a command for some reasn (e.g., uknown action type).
|
||||
*/
|
||||
public class CommandConstructionException extends Exception {
|
||||
|
||||
/**
|
||||
* Constructs the exception with a given message.
|
||||
* @param message Message to store.
|
||||
*/
|
||||
public CommandConstructionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the exception with a given message and cause.
|
||||
* @param message Message to store.
|
||||
* @param cause Cause to store.
|
||||
*/
|
||||
public CommandConstructionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package mock.model;
|
||||
|
||||
|
||||
import shared.model.Bearing;
|
||||
import shared.model.Wind;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This class generates Wind objects for use in a MockRace.
|
||||
* Initialised with a baseline wind speed and direction, and keeps it constant.
|
||||
*/
|
||||
public class ConstantWindGenerator implements WindGenerator {
|
||||
|
||||
/**
|
||||
* The bearing the wind direction starts at.
|
||||
*/
|
||||
private Bearing windBaselineBearing;
|
||||
|
||||
|
||||
/**
|
||||
* The speed the wind starts at, in knots.
|
||||
*/
|
||||
private double windBaselineSpeed;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a constant wind generator, with a baseline wind speed and direction.
|
||||
* @param windBaselineBearing Baseline wind direction.
|
||||
* @param windBaselineSpeed Baseline wind speed, in knots.
|
||||
*/
|
||||
public ConstantWindGenerator(Bearing windBaselineBearing, double windBaselineSpeed) {
|
||||
|
||||
this.windBaselineBearing = windBaselineBearing;
|
||||
this.windBaselineSpeed = windBaselineSpeed;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Wind generateBaselineWind() {
|
||||
return new Wind(windBaselineBearing, windBaselineSpeed);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Wind generateNextWind(Wind currentWind) {
|
||||
|
||||
return generateBaselineWind();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,242 @@
|
||||
package mock.model;
|
||||
|
||||
|
||||
import shared.model.Bearing;
|
||||
import shared.model.Wind;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This class generates Wind objects for use in a MockRace.
|
||||
* Bounds on bearing and speed can be specified.
|
||||
* Wind can be completely random, or random incremental change.
|
||||
*/
|
||||
public class RandomWindGenerator implements WindGenerator {
|
||||
|
||||
/**
|
||||
* The bearing the wind direction starts at.
|
||||
*/
|
||||
private Bearing windBaselineBearing;
|
||||
|
||||
/**
|
||||
* The lower bearing angle that the wind may have.
|
||||
*/
|
||||
private Bearing windBearingLowerBound;
|
||||
|
||||
/**
|
||||
* The upper bearing angle that the wind may have.
|
||||
*/
|
||||
private Bearing windBearingUpperBound;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The speed the wind starts at, in knots.
|
||||
*/
|
||||
private double windBaselineSpeed;
|
||||
|
||||
/**
|
||||
* The lower speed that the wind may have, in knots.
|
||||
*/
|
||||
private double windSpeedLowerBound;
|
||||
|
||||
/**
|
||||
* The upper speed that the wind may have, in knots.
|
||||
*/
|
||||
private double windSpeedUpperBound;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a wind generator, with a baseline, lower bound, and upper bound, for the wind speed and direction.
|
||||
* @param windBaselineBearing Baseline wind direction.
|
||||
* @param windBearingLowerBound Lower bound for wind direction.
|
||||
* @param windBearingUpperBound Upper bound for wind direction.
|
||||
* @param windBaselineSpeed Baseline wind speed, in knots.
|
||||
* @param windSpeedLowerBound Lower bound for wind speed, in knots.
|
||||
* @param windSpeedUpperBound Upper bound for wind speed, in knots.
|
||||
*/
|
||||
public RandomWindGenerator(Bearing windBaselineBearing, Bearing windBearingLowerBound, Bearing windBearingUpperBound, double windBaselineSpeed, double windSpeedLowerBound, double windSpeedUpperBound) {
|
||||
|
||||
this.windBaselineBearing = windBaselineBearing;
|
||||
this.windBearingLowerBound = windBearingLowerBound;
|
||||
this.windBearingUpperBound = windBearingUpperBound;
|
||||
this.windBaselineSpeed = windBaselineSpeed;
|
||||
this.windSpeedLowerBound = windSpeedLowerBound;
|
||||
this.windSpeedUpperBound = windSpeedUpperBound;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Wind generateBaselineWind() {
|
||||
return new Wind(windBaselineBearing, windBaselineSpeed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random Wind object, that is within the provided bounds.
|
||||
* @return Generated wind object.
|
||||
*/
|
||||
public Wind generateRandomWind() {
|
||||
|
||||
double windSpeed = generateRandomWindSpeed();
|
||||
Bearing windBearing = generateRandomWindBearing();
|
||||
|
||||
return new Wind(windBearing, windSpeed);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random wind speed within the specified bounds. In knots.
|
||||
* @return Wind speed, in knots.
|
||||
*/
|
||||
private double generateRandomWindSpeed() {
|
||||
|
||||
double randomSpeedKnots = generateRandomValueInBounds(windSpeedLowerBound, windSpeedUpperBound);
|
||||
|
||||
return randomSpeedKnots;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a random wind bearing within the specified bounds.
|
||||
* @return Wind bearing.
|
||||
*/
|
||||
private Bearing generateRandomWindBearing() {
|
||||
|
||||
double randomBearingDegrees = generateRandomValueInBounds(windBearingLowerBound.degrees(), windBearingUpperBound.degrees());
|
||||
|
||||
return Bearing.fromDegrees(randomBearingDegrees);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a random value within a specified interval.
|
||||
* @param lowerBound The lower bound of the interval.
|
||||
* @param upperBound The upper bound of the interval.
|
||||
* @return A random value within the interval.
|
||||
*/
|
||||
private static double generateRandomValueInBounds(double lowerBound, double upperBound) {
|
||||
|
||||
float proportion = new Random().nextFloat();
|
||||
|
||||
double delta = upperBound - lowerBound;
|
||||
|
||||
double amount = delta * proportion;
|
||||
|
||||
double finalAmount = amount + lowerBound;
|
||||
|
||||
return finalAmount;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a new value within an interval, given a start value, chance to change, and change amount.
|
||||
* @param lowerBound Lower bound of interval.
|
||||
* @param upperBound Upper bound of interval.
|
||||
* @param currentValue The current value to change.
|
||||
* @param changeAmount The amount to change by.
|
||||
* @param chanceToChange The change to actually change the value.
|
||||
* @return The new value.
|
||||
*/
|
||||
private static double generateNextValueInBounds(double lowerBound, double upperBound, double currentValue, double changeAmount, double chanceToChange) {
|
||||
|
||||
float chance = new Random().nextFloat();
|
||||
|
||||
|
||||
if (chance <= chanceToChange) {
|
||||
currentValue += changeAmount;
|
||||
|
||||
} else if (chance <= (2 * chanceToChange)) {
|
||||
currentValue -= changeAmount;
|
||||
|
||||
}
|
||||
|
||||
currentValue = clamp(lowerBound, upperBound, currentValue);
|
||||
|
||||
return currentValue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Wind generateNextWind(Wind currentWind) {
|
||||
|
||||
double windSpeed = generateNextWindSpeed(currentWind.getWindSpeed());
|
||||
Bearing windBearing = generateNextWindBearing(currentWind.getWindDirection());
|
||||
|
||||
return new Wind(windBearing, windSpeed);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates the next wind speed to use.
|
||||
* @param windSpeed Current wind speed, in knots.
|
||||
* @return Next wind speed, in knots.
|
||||
*/
|
||||
private double generateNextWindSpeed(double windSpeed) {
|
||||
|
||||
double chanceToChange = 0.2;
|
||||
double changeAmount = 0.1;
|
||||
|
||||
double nextWindSpeed = generateNextValueInBounds(
|
||||
windSpeedLowerBound,
|
||||
windSpeedUpperBound,
|
||||
windSpeed,
|
||||
changeAmount,
|
||||
chanceToChange);
|
||||
|
||||
return nextWindSpeed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates the next wind speed to use.
|
||||
* @param windBearing Current wind bearing.
|
||||
* @return Next wind speed.
|
||||
*/
|
||||
private Bearing generateNextWindBearing(Bearing windBearing) {
|
||||
|
||||
double chanceToChange = 0.2;
|
||||
double changeAmount = 0.5;
|
||||
|
||||
double nextWindBearingDegrees = generateNextValueInBounds(
|
||||
windBearingLowerBound.degrees(),
|
||||
windBearingUpperBound.degrees(),
|
||||
windBearing.degrees(),
|
||||
changeAmount,
|
||||
chanceToChange);
|
||||
|
||||
return Bearing.fromDegrees(nextWindBearingDegrees);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Clamps a value to be within an interval.
|
||||
* @param lower Lower bound of the interval.
|
||||
* @param upper Upper bound of the interval.
|
||||
* @param value Value to clamp.
|
||||
* @return The clamped value.
|
||||
*/
|
||||
private static double clamp(double lower, double upper, double value) {
|
||||
|
||||
if (value > upper) {
|
||||
value = upper;
|
||||
|
||||
} else if (value < lower) {
|
||||
value = lower;
|
||||
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,249 +1,29 @@
|
||||
package mock.model;
|
||||
|
||||
|
||||
import shared.model.Bearing;
|
||||
import shared.model.Wind;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This class generates Wind objects for use in a MockRace.
|
||||
* Bounds on bearing and speed can be specified.
|
||||
* Wind can be completely random, or random incremental change.
|
||||
*/
|
||||
public class WindGenerator {
|
||||
|
||||
/**
|
||||
* The bearing the wind direction starts at.
|
||||
*/
|
||||
private Bearing windBaselineBearing;
|
||||
|
||||
/**
|
||||
* The lower bearing angle that the wind may have.
|
||||
*/
|
||||
private Bearing windBearingLowerBound;
|
||||
|
||||
/**
|
||||
* The upper bearing angle that the wind may have.
|
||||
*/
|
||||
private Bearing windBearingUpperBound;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The speed the wind starts at, in knots.
|
||||
*/
|
||||
private double windBaselineSpeed;
|
||||
|
||||
/**
|
||||
* The lower speed that the wind may have, in knots.
|
||||
*/
|
||||
private double windSpeedLowerBound;
|
||||
|
||||
/**
|
||||
* The upper speed that the wind may have, in knots.
|
||||
*/
|
||||
private double windSpeedUpperBound;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a wind generator, with a baseline, lower bound, and upper bound, for the wind speed and direction.
|
||||
* @param windBaselineBearing Baseline wind direction.
|
||||
* @param windBearingLowerBound Lower bound for wind direction.
|
||||
* @param windBearingUpperBound Upper bound for wind direction.
|
||||
* @param windBaselineSpeed Baseline wind speed, in knots.
|
||||
* @param windSpeedLowerBound Lower bound for wind speed, in knots.
|
||||
* @param windSpeedUpperBound Upper bound for wind speed, in knots.
|
||||
* Interface for wind generators. It allows for generating a baseline wind, and subsequent winds.
|
||||
*/
|
||||
public WindGenerator(Bearing windBaselineBearing, Bearing windBearingLowerBound, Bearing windBearingUpperBound, double windBaselineSpeed, double windSpeedLowerBound, double windSpeedUpperBound) {
|
||||
|
||||
this.windBaselineBearing = windBaselineBearing;
|
||||
this.windBearingLowerBound = windBearingLowerBound;
|
||||
this.windBearingUpperBound = windBearingUpperBound;
|
||||
this.windBaselineSpeed = windBaselineSpeed;
|
||||
this.windSpeedLowerBound = windSpeedLowerBound;
|
||||
this.windSpeedUpperBound = windSpeedUpperBound;
|
||||
public interface WindGenerator {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a wind object using the baseline wind speed and bearing.
|
||||
* @return Baseline wind object.
|
||||
*/
|
||||
public Wind generateBaselineWind() {
|
||||
return new Wind(windBaselineBearing, windBaselineSpeed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random Wind object, that is within the provided bounds.
|
||||
* @return Generated wind object.
|
||||
*/
|
||||
public Wind generateRandomWind() {
|
||||
|
||||
double windSpeed = generateRandomWindSpeed();
|
||||
Bearing windBearing = generateRandomWindBearing();
|
||||
|
||||
return new Wind(windBearing, windSpeed);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random wind speed within the specified bounds. In knots.
|
||||
* @return Wind speed, in knots.
|
||||
*/
|
||||
private double generateRandomWindSpeed() {
|
||||
|
||||
double randomSpeedKnots = generateRandomValueInBounds(windSpeedLowerBound, windSpeedUpperBound);
|
||||
|
||||
return randomSpeedKnots;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a random wind bearing within the specified bounds.
|
||||
* @return Wind bearing.
|
||||
*/
|
||||
private Bearing generateRandomWindBearing() {
|
||||
|
||||
double randomBearingDegrees = generateRandomValueInBounds(windBearingLowerBound.degrees(), windBearingUpperBound.degrees());
|
||||
|
||||
return Bearing.fromDegrees(randomBearingDegrees);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a random value within a specified interval.
|
||||
* @param lowerBound The lower bound of the interval.
|
||||
* @param upperBound The upper bound of the interval.
|
||||
* @return A random value within the interval.
|
||||
*/
|
||||
private static double generateRandomValueInBounds(double lowerBound, double upperBound) {
|
||||
Wind generateBaselineWind();
|
||||
|
||||
float proportion = new Random().nextFloat();
|
||||
|
||||
double delta = upperBound - lowerBound;
|
||||
|
||||
double amount = delta * proportion;
|
||||
|
||||
double finalAmount = amount + lowerBound;
|
||||
|
||||
return finalAmount;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a new value within an interval, given a start value, chance to change, and change amount.
|
||||
* @param lowerBound Lower bound of interval.
|
||||
* @param upperBound Upper bound of interval.
|
||||
* @param currentValue The current value to change.
|
||||
* @param changeAmount The amount to change by.
|
||||
* @param chanceToChange The change to actually change the value.
|
||||
* @return The new value.
|
||||
*/
|
||||
private static double generateNextValueInBounds(double lowerBound, double upperBound, double currentValue, double changeAmount, double chanceToChange) {
|
||||
|
||||
float chance = new Random().nextFloat();
|
||||
|
||||
|
||||
if (chance <= chanceToChange) {
|
||||
currentValue += changeAmount;
|
||||
|
||||
} else if (chance <= (2 * chanceToChange)) {
|
||||
currentValue -= changeAmount;
|
||||
|
||||
}
|
||||
|
||||
currentValue = clamp(lowerBound, upperBound, currentValue);
|
||||
|
||||
return currentValue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates the next Wind object, that is within the provided bounds. This randomly increases or decreases the wind's speed and bearing.
|
||||
* Generates the next Wind object, according to the implementation of the wind generator.
|
||||
* @param currentWind The current wind to change. This is not modified.
|
||||
* @return Generated wind object.
|
||||
*/
|
||||
public Wind generateNextWind(Wind currentWind) {
|
||||
|
||||
double windSpeed = generateNextWindSpeed(currentWind.getWindSpeed());
|
||||
Bearing windBearing = generateNextWindBearing(currentWind.getWindDirection());
|
||||
|
||||
return new Wind(windBearing, windSpeed);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates the next wind speed to use.
|
||||
* @param windSpeed Current wind speed, in knots.
|
||||
* @return Next wind speed, in knots.
|
||||
*/
|
||||
private double generateNextWindSpeed(double windSpeed) {
|
||||
|
||||
double chanceToChange = 0.2;
|
||||
double changeAmount = 0.1;
|
||||
|
||||
double nextWindSpeed = generateNextValueInBounds(
|
||||
windSpeedLowerBound,
|
||||
windSpeedUpperBound,
|
||||
windSpeed,
|
||||
changeAmount,
|
||||
chanceToChange);
|
||||
|
||||
return nextWindSpeed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates the next wind speed to use.
|
||||
* @param windBearing Current wind bearing.
|
||||
* @return Next wind speed.
|
||||
*/
|
||||
private Bearing generateNextWindBearing(Bearing windBearing) {
|
||||
|
||||
double chanceToChange = 0.2;
|
||||
double changeAmount = 0.5;
|
||||
|
||||
double nextWindBearingDegrees = generateNextValueInBounds(
|
||||
windBearingLowerBound.degrees(),
|
||||
windBearingUpperBound.degrees(),
|
||||
windBearing.degrees(),
|
||||
changeAmount,
|
||||
chanceToChange);
|
||||
|
||||
return Bearing.fromDegrees(nextWindBearingDegrees);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Clamps a value to be within an interval.
|
||||
* @param lower Lower bound of the interval.
|
||||
* @param upper Upper bound of the interval.
|
||||
* @param value Value to clamp.
|
||||
* @return The clamped value.
|
||||
*/
|
||||
private static double clamp(double lower, double upper, double value) {
|
||||
|
||||
if (value > upper) {
|
||||
value = upper;
|
||||
|
||||
} else if (value < lower) {
|
||||
value = lower;
|
||||
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Wind generateNextWind(Wind currentWind);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,25 +1,24 @@
|
||||
package mock.model.commandFactory;
|
||||
|
||||
import mock.model.MockRace;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* Wraps multiple commands into a composite to execute queued commands during a frame.
|
||||
*/
|
||||
public class CompositeCommand implements Command {
|
||||
private Stack<Command> commands;
|
||||
private Queue<Command> commands;
|
||||
|
||||
public CompositeCommand() {
|
||||
this.commands = new Stack<>();
|
||||
this.commands = new ArrayDeque<>();
|
||||
}
|
||||
|
||||
public void addCommand(Command command) {
|
||||
commands.push(command);
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MockRace race) {
|
||||
while(!commands.isEmpty()) commands.pop().execute(race);
|
||||
public void execute() {
|
||||
while(!commands.isEmpty()) commands.remove().execute();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package mock.model.commandFactory;
|
||||
|
||||
import mock.model.MockBoat;
|
||||
import mock.model.MockRace;
|
||||
import shared.model.Bearing;
|
||||
|
||||
/**
|
||||
* Created by connortaylorbrown on 4/08/17.
|
||||
*/
|
||||
public class WindCommand implements Command {
|
||||
private MockRace race;
|
||||
private MockBoat boat;
|
||||
private int direction;
|
||||
|
||||
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
|
||||
this.race = race;
|
||||
this.boat = boat;
|
||||
this.direction = upwind? -1 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
boat.setAutoVMG(false);
|
||||
|
||||
double wind = race.getWindDirection().degrees();
|
||||
double heading = boat.getBearing().degrees();
|
||||
|
||||
double offset = 3.0;
|
||||
|
||||
offset *= direction;
|
||||
double headWindDelta = wind - heading;
|
||||
if ((headWindDelta < 0) || (headWindDelta > 180)) offset *= -1;
|
||||
|
||||
boat.setBearing(Bearing.fromDegrees(heading + offset));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<Race>
|
||||
<RaceID>5326</RaceID>
|
||||
<RaceType>FLEET</RaceType>
|
||||
<CreationTimeDate>CREATION_TIME</CreationTimeDate>
|
||||
<RaceStartTime Postpone="false" Time="START_TIME"/>
|
||||
<Participants>
|
||||
<Yacht SourceID="126"/>
|
||||
</Participants>
|
||||
<CompoundMarkSequence>
|
||||
<Corner CompoundMarkID="1" SeqID="1"/>
|
||||
<Corner CompoundMarkID="2" SeqID="2"/>
|
||||
<Corner CompoundMarkID="4" SeqID="3"/>
|
||||
<Corner CompoundMarkID="3" SeqID="4"/>
|
||||
<Corner CompoundMarkID="4" SeqID="5"/>
|
||||
<Corner CompoundMarkID="5" SeqID="6"/>
|
||||
</CompoundMarkSequence>
|
||||
<Course>
|
||||
<CompoundMark CompoundMarkID="1" Name="Start Line">
|
||||
<Mark SeqId="1" Name="PRO" TargetLat="32.296577" TargetLng="-64.854304" SourceID="101"/>
|
||||
<Mark SeqId="2" Name="PIN" TargetLat="32.293771" TargetLng="-64.855242" SourceID="102"/>
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="2" Name="Marker 1">
|
||||
<Mark Name="Marker1" TargetLat="32.293039" TargetLng="-64.843983" SourceID="103"/>
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="3" Name="Windward Gate">
|
||||
<Mark Name="WGL" SeqId="1" TargetLat="32.28468" TargetLng="-64.850045" SourceID="104"/>
|
||||
<Mark Name="WGR" SeqId="2" TargetLat="32.280164" TargetLng="-64.847591" SourceID="105"/>
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="4" Name="Leeward Gate">
|
||||
<Mark Name="LGL" SeqId="1" TargetLat="32.309693" TargetLng="-64.835249" SourceID="106"/>
|
||||
<Mark Name="LGR" SeqId="2" TargetLat="32.308046" TargetLng="-64.831785" SourceID="107"/>
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="5" Name="Finish Line">
|
||||
<Mark Name="FL" SeqId="1" TargetLat="32.317379" TargetLng="-64.839291" SourceID="108"/>
|
||||
<Mark Name="FR" SeqId="2" TargetLat="32.317257" TargetLng="-64.83626" SourceID="109"/>
|
||||
</CompoundMark>
|
||||
</Course>
|
||||
<CourseLimit>
|
||||
<Limit Lat="32.313922" Lon="-64.837168" SeqID="1"/>
|
||||
<Limit Lat="32.317379" Lon="-64.839291" SeqID="2"/>
|
||||
<Limit Lat="32.317911" Lon="-64.836996" SeqID="3"/>
|
||||
<Limit Lat="32.317257" Lon="-64.83626" SeqID="4"/>
|
||||
<Limit Lat="32.304273" Lon="-64.822834" SeqID="5"/>
|
||||
<Limit Lat="32.279097" Lon="-64.841545" SeqID="6"/>
|
||||
<Limit Lat="32.279604" Lon="-64.849871" SeqID="7"/>
|
||||
<Limit Lat="32.289545" Lon="-64.854162" SeqID="8"/>
|
||||
<Limit Lat="32.290198" Lon="-64.858711" SeqID="9"/>
|
||||
<Limit Lat="32.297164" Lon="-64.856394" SeqID="10"/>
|
||||
<Limit Lat="32.296148" Lon="-64.849184" SeqID="11"/>
|
||||
</CourseLimit>
|
||||
</Race>
|
||||
@ -0,0 +1,72 @@
|
||||
package mock.model;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import shared.model.Bearing;
|
||||
import shared.model.Wind;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the {@link ConstantWindGenerator}.
|
||||
*/
|
||||
public class ConstantWindGeneratorTest {
|
||||
|
||||
WindGenerator windGenerator;
|
||||
Bearing windBearing;
|
||||
double windSpeedKnots;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
windBearing = Bearing.fromDegrees(78.5);
|
||||
windSpeedKnots = 18.54;
|
||||
|
||||
windGenerator = new ConstantWindGenerator(windBearing, windSpeedKnots);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if the {@link WindGenerator#generateBaselineWind()} function works.
|
||||
*/
|
||||
@Test
|
||||
public void generateBaselineTest() {
|
||||
|
||||
int repetitions = 100;
|
||||
|
||||
for (int i = 0; i < repetitions; i++) {
|
||||
|
||||
Wind wind = windGenerator.generateBaselineWind();
|
||||
|
||||
assertEquals(windBearing.degrees(), wind.getWindDirection().degrees(), 0.01);
|
||||
assertEquals(windSpeedKnots, wind.getWindSpeed(), 0.01);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if the {@link WindGenerator#generateNextWind(Wind)} ()} function works.
|
||||
*/
|
||||
@Test
|
||||
public void generateNextWindTest() {
|
||||
|
||||
int repetitions = 100;
|
||||
|
||||
Wind wind = windGenerator.generateBaselineWind();
|
||||
|
||||
for (int i = 0; i < repetitions; i++) {
|
||||
|
||||
wind = windGenerator.generateNextWind(wind);
|
||||
|
||||
assertEquals(windBearing.degrees(), wind.getWindDirection().degrees(), 0.01);
|
||||
assertEquals(windSpeedKnots, wind.getWindSpeed(), 0.01);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,7 +1,44 @@
|
||||
package mock.model;
|
||||
|
||||
import mock.dataInput.PolarParserTest;
|
||||
import network.Messages.LatestMessages;
|
||||
import shared.dataInput.*;
|
||||
import shared.exceptions.InvalidBoatDataException;
|
||||
import shared.exceptions.InvalidRaceDataException;
|
||||
import shared.exceptions.InvalidRegattaDataException;
|
||||
import shared.model.Bearing;
|
||||
import shared.model.Constants;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class MockRaceTest {
|
||||
//TODO
|
||||
|
||||
|
||||
/**
|
||||
* Creates a MockRace for use in testing.
|
||||
* Has a constant wind generator.
|
||||
* @return MockRace for testing.
|
||||
* @throws InvalidBoatDataException
|
||||
* @throws InvalidRaceDataException
|
||||
* @throws InvalidRegattaDataException
|
||||
*/
|
||||
public static MockRace createMockRace() throws InvalidBoatDataException, InvalidRaceDataException, InvalidRegattaDataException {
|
||||
|
||||
BoatDataSource boatDataSource = BoatXMLReaderTest.createBoatDataSource();
|
||||
RaceDataSource raceDataSource = RaceXMLReaderTest.createRaceDataSource();
|
||||
RegattaDataSource regattaDataSource = RegattaXMLReaderTest.createRegattaDataSource();
|
||||
|
||||
LatestMessages latestMessages = new LatestMessages();
|
||||
|
||||
Polars polars = PolarParserTest.createPolars();
|
||||
|
||||
WindGenerator windGenerator = new ConstantWindGenerator(Bearing.fromDegrees(230), 10);
|
||||
|
||||
MockRace mockRace = new MockRace(boatDataSource, raceDataSource, regattaDataSource, latestMessages, polars, Constants.RaceTimeScale, windGenerator);
|
||||
|
||||
|
||||
return mockRace;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,31 +1,72 @@
|
||||
package mock.model.commandFactory;
|
||||
|
||||
import mock.exceptions.CommandConstructionException;
|
||||
import mock.model.MockBoat;
|
||||
import mock.model.MockRace;
|
||||
import mock.model.MockRaceTest;
|
||||
import network.Messages.BoatAction;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import shared.exceptions.InvalidBoatDataException;
|
||||
import shared.exceptions.InvalidRaceDataException;
|
||||
import shared.exceptions.InvalidRegattaDataException;
|
||||
import shared.model.Bearing;
|
||||
import shared.model.Boat;
|
||||
import shared.model.Race;
|
||||
import visualiser.model.VisualiserRace;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.testng.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Created by connortaylorbrown on 4/08/17.
|
||||
*/
|
||||
public class WindCommandTest {
|
||||
private Race race;
|
||||
private Boat boat;
|
||||
private MockRace race;
|
||||
private MockBoat boat;
|
||||
private Command upwind;
|
||||
private Command downwind;
|
||||
private double initial;
|
||||
|
||||
private double offset = 3.0;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
boat = new Boat(0, "Bob", "NZ");
|
||||
public void setUp() throws CommandConstructionException, InvalidBoatDataException, InvalidRegattaDataException, InvalidRaceDataException {
|
||||
race = MockRaceTest.createMockRace();
|
||||
|
||||
boat = race.getBoats().get(0);
|
||||
|
||||
|
||||
//when(race.getWindDirection()).thenReturn(Bearing.fromDegrees(0.0));
|
||||
boat.setBearing(Bearing.fromDegrees(45.0));
|
||||
|
||||
BoatAction upwindAction = new BoatAction(BoatActionEnum.UPWIND);
|
||||
upwindAction.setSourceID(boat.getSourceID());
|
||||
|
||||
BoatAction downwindAction = new BoatAction(BoatActionEnum.DOWNWIND);
|
||||
downwindAction.setSourceID(boat.getSourceID());
|
||||
|
||||
upwind = CommandFactory.createCommand(race, upwindAction);
|
||||
downwind = CommandFactory.createCommand(race, downwindAction);
|
||||
|
||||
initial = boat.getBearing().degrees();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the difference between initial and final angle is 3 degrees
|
||||
*/
|
||||
@Test
|
||||
public void upwindCommandDecreasesAngle() {
|
||||
upwind.execute();
|
||||
assertEquals(initial - boat.getBearing().degrees(), -offset, 1e-5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downwindCommandIncreasesAngle() {
|
||||
downwind.execute();
|
||||
assertEquals(initial - boat.getBearing().degrees(), offset, 1e-5);
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,39 @@
|
||||
package shared.dataInput;
|
||||
|
||||
import shared.enums.XMLFileType;
|
||||
import shared.exceptions.InvalidRaceDataException;
|
||||
import shared.exceptions.XMLReaderException;
|
||||
|
||||
import javax.xml.transform.TransformerException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class RaceXMLReaderTest {
|
||||
//TODO
|
||||
|
||||
|
||||
|
||||
public static RaceDataSource createRaceDataSource() throws InvalidRaceDataException {
|
||||
|
||||
String raceXMLString = null;
|
||||
|
||||
try {
|
||||
raceXMLString = XMLReader.readXMLFileToString("mock/mockXML/raceTest.xml", StandardCharsets.UTF_8);
|
||||
|
||||
} catch (TransformerException | XMLReaderException e) {
|
||||
throw new InvalidRaceDataException("Could not read race XML file into a string.", e);
|
||||
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
|
||||
RaceXMLReader raceData = new RaceXMLReader(raceXMLString, XMLFileType.Contents);
|
||||
return raceData;
|
||||
|
||||
|
||||
} catch (XMLReaderException e) {
|
||||
throw new InvalidRaceDataException("Could not parse race XML file.", e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue