mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge branch 'develop' into story61_player_perspective
# Conflicts: # src/main/java/seng302/App.java # src/main/java/seng302/client/ClientPacketParser.java # src/main/java/seng302/controllers/Controller.java # src/main/java/seng302/controllers/RaceViewController.java # src/main/java/seng302/fxObjects/BoatAnnotations.java # src/main/java/seng302/gameServer/GameState.java # src/main/java/seng302/gameServer/MainServerThread.java # src/main/java/seng302/gameServer/ServerToClientThread.java # src/main/java/seng302/model/Boat.java # src/main/java/seng302/models/stream/XMLParser.java # src/main/java/seng302/visualiser/ClientToServerThread.java # src/main/java/seng302/visualiser/GameView.java # src/main/java/seng302/visualiser/controllers/FinishScreenViewController.java # src/main/java/seng302/visualiser/controllers/StartScreenController.java # src/main/java/seng302/visualiser/fxObjects/BoatObject.java # src/main/resources/views/LobbyView.fxml # src/main/resources/views/MainView.fxml
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package seng302.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -123,7 +127,7 @@ public final class PolarTable {
|
||||
*/
|
||||
public static HashMap<Double, Double> getOptimalUpwindVMG(Double thisWindSpeed) {
|
||||
|
||||
Double polarWindSpeed = getClosestMatch(thisWindSpeed);
|
||||
Double polarWindSpeed = getClosestWindSpeedInPolar(thisWindSpeed);
|
||||
return upwindOptimal.get(polarWindSpeed);
|
||||
}
|
||||
|
||||
@@ -135,30 +139,47 @@ public final class PolarTable {
|
||||
*/
|
||||
public static HashMap<Double, Double> getOptimalDownwindVMG(Double thisWindSpeed) {
|
||||
|
||||
Double polarWindSpeed = getClosestMatch(thisWindSpeed);
|
||||
Double polarWindSpeed = getClosestWindSpeedInPolar(thisWindSpeed);
|
||||
return downwindOptimal.get(polarWindSpeed);
|
||||
}
|
||||
|
||||
|
||||
private static Double getClosestMatch(Double thisWindSpeed) {
|
||||
public static Double getBoatSpeed(Double thisWindSpeed, Double thisHeading) {
|
||||
|
||||
ArrayList<Double> windValues = new ArrayList<>(polarTable.keySet());
|
||||
Double polarWindSpeed = getClosestWindSpeedInPolar(thisWindSpeed);
|
||||
Double polarAngle = getClosestAngleInPolar(polarTable.get(polarWindSpeed), thisHeading);
|
||||
|
||||
Double lowerVal = windValues.get(0);
|
||||
Double upperVal = windValues.get(1);
|
||||
return polarTable.get(polarWindSpeed).get(polarAngle);
|
||||
}
|
||||
|
||||
for(int i = 0; i < windValues.size() - 1; i++) {
|
||||
lowerVal = windValues.get(i);
|
||||
upperVal = windValues.get(i+1);
|
||||
if (thisWindSpeed <= upperVal) {
|
||||
break;
|
||||
|
||||
public static Double getClosestWindSpeedInPolar(Double thisWindSpeed) {
|
||||
Double smallestDif = Double.POSITIVE_INFINITY;
|
||||
Double closestWind = 0d;
|
||||
|
||||
for (Double polarWindSpeed : polarTable.keySet()) {
|
||||
Double difference = Math.abs(polarWindSpeed - thisWindSpeed);
|
||||
if (difference < smallestDif) {
|
||||
smallestDif = difference;
|
||||
closestWind = polarWindSpeed;
|
||||
}
|
||||
}
|
||||
return closestWind;
|
||||
}
|
||||
|
||||
Double lowerDiff = Math.abs(lowerVal - thisWindSpeed);
|
||||
Double upperDiff = Math.abs(upperVal - thisWindSpeed);
|
||||
|
||||
return (lowerDiff <= upperDiff) ? lowerVal : upperVal;
|
||||
public static Double getClosestAngleInPolar(HashMap<Double, Double> thisWindSpeedPolar, Double thisHeading) {
|
||||
Double smallestDif = Double.POSITIVE_INFINITY;
|
||||
Double closestAngle = 0d;
|
||||
|
||||
for (Double polarAngle : thisWindSpeedPolar.keySet()) {
|
||||
Double difference = Math.abs(polarAngle - thisHeading);
|
||||
if (difference < smallestDif) {
|
||||
smallestDif = difference;
|
||||
closestAngle = polarAngle;
|
||||
}
|
||||
}
|
||||
return closestAngle;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user