mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Improved boat bounce-back calculation
- Changed boat bounce back send the boat n meters in the opposite direction. - Improved test to use the minimum of yacht and mark collision distances Tags: #story[1117]
This commit is contained in:
@@ -180,3 +180,7 @@ local.properties
|
|||||||
.recommenders/
|
.recommenders/
|
||||||
|
|
||||||
Makefile
|
Makefile
|
||||||
|
|
||||||
|
infer-out/
|
||||||
|
infer.txt
|
||||||
|
log.log
|
||||||
@@ -1,14 +1,5 @@
|
|||||||
package seng302.model;
|
package seng302.model;
|
||||||
|
|
||||||
import static seng302.utilities.GeoUtility.getGeoCoordinate;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javafx.beans.property.ReadOnlyDoubleProperty;
|
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||||
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||||
import javafx.beans.property.ReadOnlyLongProperty;
|
import javafx.beans.property.ReadOnlyLongProperty;
|
||||||
@@ -19,6 +10,15 @@ import seng302.model.mark.CompoundMark;
|
|||||||
import seng302.model.mark.Mark;
|
import seng302.model.mark.Mark;
|
||||||
import seng302.utilities.GeoUtility;
|
import seng302.utilities.GeoUtility;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static seng302.utilities.GeoUtility.getGeoCoordinate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Yacht class for the racing boat.
|
* Yacht class for the racing boat.
|
||||||
*
|
*
|
||||||
@@ -33,8 +33,9 @@ public class Yacht {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final Double ROUNDING_DISTANCE = 15d; // TODO: 3/08/17 wmu16 - Look into this value further
|
private static final Double ROUNDING_DISTANCE = 15d; // TODO: 3/08/17 wmu16 - Look into this value further
|
||||||
public static final Double MARK_COLLISION_DISTANCE = ROUNDING_DISTANCE - 8d;
|
public static final Double MARK_COLLISION_DISTANCE = 15d;
|
||||||
private static final Double BOUNCE_FACTOR = 0.0001;
|
public static final Double YACHT_COLLISION_DISTANCE = 25.0;
|
||||||
|
private static final Double BOUNCE_DISTANCE = 20.0;
|
||||||
private static final Integer COLLISION_UPDATE_INTERVAL = 100;
|
private static final Integer COLLISION_UPDATE_INTERVAL = 100;
|
||||||
|
|
||||||
//BOTH AFAIK
|
//BOTH AFAIK
|
||||||
@@ -184,27 +185,13 @@ public class Yacht {
|
|||||||
* @return The boats new position
|
* @return The boats new position
|
||||||
*/
|
*/
|
||||||
private GeoPoint calculateBounceBack(GeoPoint collidedWith){
|
private GeoPoint calculateBounceBack(GeoPoint collidedWith){
|
||||||
Double lat = location.getLat();
|
|
||||||
Double lon = location.getLng();
|
|
||||||
|
|
||||||
Double heading = GeoUtility.getBearing(location, collidedWith);
|
Double heading = GeoUtility.getBearing(location, collidedWith);
|
||||||
|
|
||||||
|
// Invert heading
|
||||||
|
heading -= 180;
|
||||||
|
Integer newHeading = Math.floorMod(heading.intValue(), 360);
|
||||||
|
|
||||||
if (heading >= 0 && heading <= 180){
|
return GeoUtility.getGeoCoordinate(location, newHeading.doubleValue(), BOUNCE_DISTANCE);
|
||||||
lat -= BOUNCE_FACTOR;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
lat += BOUNCE_FACTOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (heading >= 90 && heading <= 360-90){
|
|
||||||
lon += BOUNCE_FACTOR;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
lon -= BOUNCE_FACTOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new GeoPoint(lat, lon);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -539,12 +526,12 @@ public class Yacht {
|
|||||||
* @return yacht which collided with this yacht
|
* @return yacht which collided with this yacht
|
||||||
*/
|
*/
|
||||||
private Yacht checkCollision(GeoPoint calculatedPoint) {
|
private Yacht checkCollision(GeoPoint calculatedPoint) {
|
||||||
Double COLLISIONFACTOR = 25.0; // Collision detection in meters
|
// Collision detection in meters
|
||||||
|
|
||||||
for (Yacht yacht : GameState.getYachts().values()) {
|
for (Yacht yacht : GameState.getYachts().values()) {
|
||||||
if (yacht != this) {
|
if (yacht != this) {
|
||||||
Double distance = GeoUtility.getDistance(yacht.getLocation(), calculatedPoint);
|
Double distance = GeoUtility.getDistance(yacht.getLocation(), calculatedPoint);
|
||||||
if (distance < COLLISIONFACTOR) {
|
if (distance < YACHT_COLLISION_DISTANCE) {
|
||||||
return yacht;
|
return yacht;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,7 @@ public class UpdateYachtTest {
|
|||||||
// Making sure no collision
|
// Making sure no collision
|
||||||
Double distance = GeoUtility.getDistance(yacht1.getLocation(), geoPoint2);
|
Double distance = GeoUtility.getDistance(yacht1.getLocation(), geoPoint2);
|
||||||
|
|
||||||
// Using mark collision distance as it will be smaller than boat collision distance
|
Assert.assertTrue(distance > Math.min(Yacht.MARK_COLLISION_DISTANCE, Yacht.YACHT_COLLISION_DISTANCE));
|
||||||
Assert.assertTrue(distance > Yacht.MARK_COLLISION_DISTANCE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user