Merge branch 'CommandFactory' into 'master'
Tacking and gybing merge request Note: this allows the player to perform a common maneuver, changing tack, quickly. The goal is to change the boat's heading from one tack to another with a single keypress. If the boat is heading upwind, the keypress will cause the boat to tack through head-to-wind, so that the wind shifts from one side of the boat to the other. The TWA (true wind angle) after tacking should be 360-TWA(before_tacking). Similarly for gybing if the boat is initially heading downwind, except that the boat's heading always remains away from the wind. Acceptance criteria: - The wind shifts from one side of the boat to the other on keypress - When heading upwind the boat should tack on keypress - When heading downwind the boat should gybe on keypress [Manual test](https://eng-git.canterbury.ac.nz/seng302-2017/team-7/wikis/manual-test:-tacking-and-gybing) See merge request !24
This commit is contained in:
Generated
-6
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectCodeStyleSettingsManager">
|
|
||||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -346,7 +346,7 @@ public class MockRace extends Race {
|
|||||||
|
|
||||||
this.updateEstimatedTime(boat);
|
this.updateEstimatedTime(boat);
|
||||||
}
|
}
|
||||||
|
checkPosition(boat, totalElapsedMilliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void newOptimalVMG(MockBoat boat) {
|
private void newOptimalVMG(MockBoat boat) {
|
||||||
@@ -688,6 +688,7 @@ public class MockRace extends Race {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<CompoundMark> getCompoundMarks() {
|
public List<CompoundMark> getCompoundMarks() {
|
||||||
return compoundMarks;
|
return compoundMarks;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class CommandFactory {
|
|||||||
* @param race to receive command
|
* @param race to receive command
|
||||||
* @param boat to receive command in race
|
* @param boat to receive command in race
|
||||||
* @param action number to select command
|
* @param action number to select command
|
||||||
* @return
|
* @return command object corresponding to action
|
||||||
*/
|
*/
|
||||||
public static Command createCommand(MockRace race, MockBoat boat, BoatActionEnum action) {
|
public static Command createCommand(MockRace race, MockBoat boat, BoatActionEnum action) {
|
||||||
switch(action) {
|
switch(action) {
|
||||||
|
|||||||
@@ -2,34 +2,49 @@ package mock.model.commandFactory;
|
|||||||
|
|
||||||
import mock.model.MockBoat;
|
import mock.model.MockBoat;
|
||||||
import mock.model.MockRace;
|
import mock.model.MockRace;
|
||||||
|
import shared.model.Bearing;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by David on 2/08/2017.
|
* Command class for tacking and gybing
|
||||||
*/
|
*/
|
||||||
public class TackGybeCommand implements Command {
|
public class TackGybeCommand implements Command {
|
||||||
private MockRace race;
|
private MockRace race;
|
||||||
private MockBoat boat;
|
private MockBoat boat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for class
|
||||||
|
* @param race mock race
|
||||||
|
* @param boat mock boat to update
|
||||||
|
*/
|
||||||
public TackGybeCommand(MockRace race, MockBoat boat) {
|
public TackGybeCommand(MockRace race, MockBoat boat) {
|
||||||
this.race = race;
|
this.race = race;
|
||||||
this.boat = boat;
|
this.boat = boat;
|
||||||
}
|
}
|
||||||
|
|
||||||
//The refactoring of MockRace will require changes to be made
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
|
double boatAngle = boat.getBearing().degrees();
|
||||||
boat.setAutoVMG(false);
|
double windAngle =race.getWindDirection().degrees();
|
||||||
|
double differenceAngle = calcDistance(boatAngle, windAngle);
|
||||||
/*VMG newVMG = boat.getPolars().calculateVMG(
|
double angleA = windAngle + differenceAngle;
|
||||||
race.getWindDirection(),
|
double angleB = windAngle - differenceAngle;
|
||||||
race.getWindSpeed(),
|
if(angleA % 360 == boatAngle){
|
||||||
boat.calculateBearingToNextMarker(),
|
boat.setBearing(Bearing.fromDegrees(angleB));
|
||||||
Bearing.fromDegrees(0d),
|
} else {
|
||||||
Bearing.fromDegrees(359.99999d));
|
boat.setBearing(Bearing.fromDegrees(angleA));
|
||||||
VMG boatVMG = new VMG(boat.getCurrentSpeed(), boat.getBearing());
|
|
||||||
if(race.improvesVelocity(boatVMG, newVMG, boat.calculateBearingToNextMarker())){
|
|
||||||
boat.setVMG(newVMG);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to calculate smallest angle between 2 angles
|
||||||
|
* @param degreeA first angle degree
|
||||||
|
* @param degreeB second angle degree
|
||||||
|
* @return the calculated smallest angle
|
||||||
|
*/
|
||||||
|
public double calcDistance(double degreeA, double degreeB){
|
||||||
|
double phi = Math.abs(degreeB - degreeA) % 360;
|
||||||
|
return phi > 180 ? 360 - phi : phi;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,27 +4,30 @@ import mock.model.MockBoat;
|
|||||||
import mock.model.MockRace;
|
import mock.model.MockRace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by David on 2/08/2017.
|
* Command class for autoVMG
|
||||||
*/
|
*/
|
||||||
public class VMGCommand implements Command {
|
public class VMGCommand implements Command {
|
||||||
private MockRace race;
|
private MockRace race;
|
||||||
private MockBoat boat;
|
private MockBoat boat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for class
|
||||||
|
* @param race mock race
|
||||||
|
* @param boat mock boat to update
|
||||||
|
*/
|
||||||
public VMGCommand(MockRace race, MockBoat boat) {
|
public VMGCommand(MockRace race, MockBoat boat) {
|
||||||
this.race = race;
|
this.race = race;
|
||||||
this.boat = boat;
|
this.boat = boat;
|
||||||
}
|
}
|
||||||
|
|
||||||
//The refactoring of MockRace will require changes to be made
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
|
if (boat.getAutoVMG()){
|
||||||
|
boat.setAutoVMG(false);
|
||||||
|
System.out.println("Auto VMG off!");
|
||||||
|
} else {
|
||||||
boat.setAutoVMG(true);
|
boat.setAutoVMG(true);
|
||||||
/*VMG newVMG = boat.getPolars().calculateVMG(
|
System.out.println("Auto VMG on!");
|
||||||
race.getWindDirection(),
|
}
|
||||||
race.getWindSpeed(),
|
|
||||||
boat.calculateBearingToNextMarker(),
|
|
||||||
Bearing.fromDegrees(0d),
|
|
||||||
Bearing.fromDegrees(359.99999d));
|
|
||||||
boat.setVMG(newVMG);*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,19 +30,15 @@ public class ControllerServer extends Observable implements Runnable {
|
|||||||
* Last received boat action
|
* Last received boat action
|
||||||
*/
|
*/
|
||||||
private BoatActionEnum action;
|
private BoatActionEnum action;
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private RaceLogic rc;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise server-side controller with live client socket
|
* Initialise server-side controller with live client socket
|
||||||
* @param socket to client
|
* @param socket to client
|
||||||
|
* @param race logic loop observing controls
|
||||||
*/
|
*/
|
||||||
public ControllerServer(Socket socket, RaceLogic rc) {
|
public ControllerServer(Socket socket, RaceLogic race) {
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
this.rc = rc;
|
this.addObserver(race);
|
||||||
this.addObserver(rc);
|
|
||||||
try {
|
try {
|
||||||
this.inputStream = new DataInputStream(this.socket.getInputStream());
|
this.inputStream = new DataInputStream(this.socket.getInputStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user