From 07386ed2db67a41c0203231dbdd4851d35469152 Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Thu, 10 Aug 2017 13:01:31 +1200 Subject: [PATCH] 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] --- .gitignore | 4 ++ src/main/java/seng302/model/Yacht.java | 49 +++++++------------ .../java/seng302/model/UpdateYachtTest.java | 3 +- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 3c15f041..213db0db 100644 --- a/.gitignore +++ b/.gitignore @@ -180,3 +180,7 @@ local.properties .recommenders/ Makefile + +infer-out/ +infer.txt +log.log \ No newline at end of file diff --git a/src/main/java/seng302/model/Yacht.java b/src/main/java/seng302/model/Yacht.java index 10a1dbfa..a3a9094a 100644 --- a/src/main/java/seng302/model/Yacht.java +++ b/src/main/java/seng302/model/Yacht.java @@ -1,14 +1,5 @@ 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.ReadOnlyDoubleWrapper; import javafx.beans.property.ReadOnlyLongProperty; @@ -19,6 +10,15 @@ import seng302.model.mark.CompoundMark; import seng302.model.mark.Mark; 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. * @@ -33,8 +33,9 @@ public class Yacht { } 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; - private static final Double BOUNCE_FACTOR = 0.0001; + public static final Double MARK_COLLISION_DISTANCE = 15d; + 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; //BOTH AFAIK @@ -184,27 +185,13 @@ public class Yacht { * @return The boats new position */ private GeoPoint calculateBounceBack(GeoPoint collidedWith){ - Double lat = location.getLat(); - Double lon = location.getLng(); - Double heading = GeoUtility.getBearing(location, collidedWith); + // Invert heading + heading -= 180; + Integer newHeading = Math.floorMod(heading.intValue(), 360); - if (heading >= 0 && heading <= 180){ - 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); + return GeoUtility.getGeoCoordinate(location, newHeading.doubleValue(), BOUNCE_DISTANCE); } @@ -539,12 +526,12 @@ public class Yacht { * @return yacht which collided with this yacht */ private Yacht checkCollision(GeoPoint calculatedPoint) { - Double COLLISIONFACTOR = 25.0; // Collision detection in meters + // Collision detection in meters for (Yacht yacht : GameState.getYachts().values()) { if (yacht != this) { Double distance = GeoUtility.getDistance(yacht.getLocation(), calculatedPoint); - if (distance < COLLISIONFACTOR) { + if (distance < YACHT_COLLISION_DISTANCE) { return yacht; } } diff --git a/src/test/java/seng302/model/UpdateYachtTest.java b/src/test/java/seng302/model/UpdateYachtTest.java index 9af9d30f..45fffa8d 100644 --- a/src/test/java/seng302/model/UpdateYachtTest.java +++ b/src/test/java/seng302/model/UpdateYachtTest.java @@ -50,8 +50,7 @@ public class UpdateYachtTest { // Making sure no collision Double distance = GeoUtility.getDistance(yacht1.getLocation(), geoPoint2); - // Using mark collision distance as it will be smaller than boat collision distance - Assert.assertTrue(distance > Yacht.MARK_COLLISION_DISTANCE); + Assert.assertTrue(distance > Math.min(Yacht.MARK_COLLISION_DISTANCE, Yacht.YACHT_COLLISION_DISTANCE)); } }