mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Added junit for update yacht (after collision implementation). Removed another version of initialise boat positions.
#story[1117]
This commit is contained in:
@@ -222,38 +222,4 @@ public class GameState implements Runnable {
|
||||
System.out.println("Lng: " + playerYacht.getLocation().getLng());
|
||||
System.out.println("-----------------------\n");
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Calculates and initialise a yacht given its index in the starting position. Position is
|
||||
// * calculated starting with 0 being the first boat. Position 0 will spawn in the MIDDLE of mark1
|
||||
// * and mark2, position 1 will spawn 50m LEFT of position 0, position 2 will spawn 50m RIGHT of
|
||||
// * position 0, position 3 will spawn 100m LEFT of position 0, and so forth.
|
||||
// *
|
||||
// * @param mark1 first mark of the starting composite mark
|
||||
// * @param mark2 second mark of the starting composite mark
|
||||
// * @param boatIndex boat starting position
|
||||
// * @param yacht yacht to be reposition
|
||||
// */
|
||||
// public static void startBoatInPosition(GeoPoint mark1, GeoPoint mark2, Integer boatIndex,
|
||||
// Yacht yacht) {
|
||||
// // TODO: 6/08/2017 zyt10 - check for mark1 being the right side from heading
|
||||
// // Calculating midpoint
|
||||
// Double perpendicularAngle = GeoUtility.getBearing(mark1, mark2);
|
||||
// Double length = GeoUtility.getDistance(mark1, mark2);
|
||||
// GeoPoint midpoint = GeoUtility.getGeoCoordinate(mark1, perpendicularAngle, length / 2);
|
||||
//
|
||||
// // Setting each boats position side by side
|
||||
// double DISTANCEFACTOR = 50.0; // distance apart in meters
|
||||
// int distanceApart = boatIndex / 2;
|
||||
//
|
||||
// if (boatIndex % 2 == 1 && boatIndex != 0) {
|
||||
// distanceApart++;
|
||||
// distanceApart *= 1;
|
||||
// }
|
||||
//
|
||||
// GeoPoint spawnMark = GeoUtility
|
||||
// .getGeoCoordinate(midpoint, perpendicularAngle, distanceApart * DISTANCEFACTOR);
|
||||
//
|
||||
// yacht.setLocation(spawnMark);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ import seng302.model.GeoPoint;
|
||||
import seng302.model.Player;
|
||||
import seng302.model.Yacht;
|
||||
import seng302.model.mark.CompoundMark;
|
||||
import seng302.model.mark.Mark;
|
||||
import seng302.model.stream.xml.parser.RaceXMLData;
|
||||
import seng302.utilities.GeoUtility;
|
||||
import seng302.visualiser.GameClient;
|
||||
|
||||
@@ -142,7 +140,7 @@ public class MainServerThread extends Observable implements Runnable, ClientConn
|
||||
}
|
||||
|
||||
public void startGame() {
|
||||
initialiseBoatPosition();
|
||||
initialiseBoatPositions();
|
||||
|
||||
Timer t = new Timer();
|
||||
|
||||
@@ -173,7 +171,7 @@ public class MainServerThread extends Observable implements Runnable, ClientConn
|
||||
/**
|
||||
* Initialise boats to specific spaced out geopoints behind starting line.
|
||||
*/
|
||||
private void initialiseBoatPosition() {
|
||||
private void initialiseBoatPositions() {
|
||||
// Getting the start line compound marks
|
||||
CompoundMark cm = gameClient.getCourseData().getCompoundMarks().get(1);
|
||||
GeoPoint startMark1 = new GeoPoint(cm.getMarks().get(0).getLat(),
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
package seng302.gameServer.server;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.gameServer.MainServerThread;
|
||||
import seng302.model.GeoPoint;
|
||||
import seng302.model.Yacht;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
/**
|
||||
* Created by ryantan on 5/08/2017.
|
||||
*/
|
||||
public class TestInitialiseBoatPosition {
|
||||
private GeoPoint mark1 = new GeoPoint(50, 50);
|
||||
private GeoPoint mark2 = new GeoPoint(0, 0);
|
||||
|
||||
private GameState gameState = new GameState("");
|
||||
|
||||
@Test
|
||||
public void testInitialiseBoatPosition(){
|
||||
// // Calculating midpoint
|
||||
// Double perpendicularAngle = GeoUtility.getBearing(mark1, mark2);
|
||||
// Double length = GeoUtility.getDistance(mark1, mark2);
|
||||
// GeoPoint midpoint = GeoUtility.getGeoCoordinate(mark1, perpendicularAngle, length / 2);
|
||||
//
|
||||
// // Create 8 yacht in game state
|
||||
// for (int i = 0; i < 8; i++) {
|
||||
// GameState.addYacht(i, new Yacht("Yacht", i, "1", "Yacht" + i, "Yacht" + i, "Test" ));
|
||||
// }
|
||||
//
|
||||
// int i = 0;
|
||||
// for (Yacht yacht : GameState.getYachts().values()) {
|
||||
// GameState.startBoatInPosition(mark1, mark2, i, yacht);
|
||||
// double distance = GeoUtility.getDistance(midpoint, yacht.getLocation());
|
||||
// System.out.println(i + " " + distance);
|
||||
//
|
||||
// double distanceApart = i / 2;
|
||||
// if (i % 2 == 1 && i != 0) {
|
||||
// distanceApart++;
|
||||
// }
|
||||
//
|
||||
// assertTrue(distance <= (distanceApart * 50.01) && distance >= (distanceApart * 49.99));
|
||||
// i++;
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package seng302.model;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
/**
|
||||
* Test update function in Yacht.java to make sure yacht will not be collide each other within 25.0
|
||||
* meters.
|
||||
*/
|
||||
public class UpdateYachtTest {
|
||||
|
||||
private Yacht yacht1 = new Yacht("Yacht", 1, "1", "Yacht" + 1, "Yacht" + 1, "Test1");
|
||||
private Yacht yacht2 = new Yacht("Yacht", 2, "2", "Yacht" + 2, "Yacht" + 2, "Test2");
|
||||
private GeoPoint geoPoint1 = new GeoPoint(50.0, 50.0);
|
||||
private GeoPoint geoPoint2 = GeoUtility.getGeoCoordinate(geoPoint1, 90.0, 50.0);
|
||||
|
||||
@Before
|
||||
public void setUpRace() {
|
||||
new GameState("");
|
||||
GameState.addYacht(1, yacht1);
|
||||
GameState.addYacht(2, yacht2);
|
||||
PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateYachtWithCollision() {
|
||||
// Yacht 1 heading towards 90 degrees heading
|
||||
yacht1.setLocation(geoPoint1);
|
||||
yacht1.updateLocation(geoPoint1.getLat(), geoPoint1.getLng(), 90.0, 5.0);
|
||||
|
||||
// Yacht 2 heading towards 270 degrees heading
|
||||
yacht2.setLocation(geoPoint2);
|
||||
yacht2.updateLocation(geoPoint2.getLat(), geoPoint2.getLng(), 270.0, 5.0);
|
||||
|
||||
// Start yacht 1 and rest yacht 2
|
||||
if (!yacht1.getSailIn()) {
|
||||
yacht1.toggleSailIn();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
yacht1.update((long) 1000);
|
||||
|
||||
// Making sure boat is moving
|
||||
double moved = GeoUtility.getDistance(yacht1.getLocation(), geoPoint1);
|
||||
Assert.assertTrue(moved > 0);
|
||||
|
||||
// Making sure no collision
|
||||
double distance = GeoUtility.getDistance(yacht1.getLocation(), geoPoint2);
|
||||
Assert.assertTrue(distance > 25.0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateYachtWithoutCollision() {
|
||||
// Yacht 1 heading towards 90 degrees heading
|
||||
yacht1.setLocation(geoPoint1);
|
||||
yacht1.updateLocation(geoPoint1.getLat(), geoPoint1.getLng(), 90.0, 5.0);
|
||||
|
||||
// Yacht 2 heading towards 90 degrees heading
|
||||
yacht2.setLocation(geoPoint2);
|
||||
yacht2.updateLocation(geoPoint2.getLat(), geoPoint2.getLng(), 90.0, 5.0);
|
||||
|
||||
// Start yacht 1 and yacht 2
|
||||
if (!yacht1.getSailIn()) {
|
||||
yacht1.toggleSailIn();
|
||||
}
|
||||
if (!yacht2.getSailIn()) {
|
||||
yacht2.toggleSailIn();
|
||||
}
|
||||
|
||||
double previousDistance1 = 0;
|
||||
double previousDistance2 = 0;
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
yacht1.update((long) 1000);
|
||||
yacht2.update((long) 1000);
|
||||
|
||||
// Making sure boat is moving
|
||||
double yachtMoved1 = GeoUtility.getDistance(yacht1.getLocation(), geoPoint1);
|
||||
Assert.assertTrue(yachtMoved1 > previousDistance1);
|
||||
previousDistance1 = yachtMoved1;
|
||||
|
||||
double yachtMoved2 = GeoUtility.getDistance(yacht2.getLocation(), geoPoint2);
|
||||
Assert.assertTrue(yachtMoved2 > previousDistance2);
|
||||
previousDistance2 = yachtMoved2;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user