Fixed wind direction code missing due to past merges (?)
#story[882]
This commit is contained in:
@@ -33,6 +33,8 @@ public class Race implements Runnable {
|
|||||||
private int raceId;
|
private int raceId;
|
||||||
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
|
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
|
||||||
private MockOutput mockOutput;
|
private MockOutput mockOutput;
|
||||||
|
private int windDir;
|
||||||
|
private int changeWind = 4;
|
||||||
|
|
||||||
public Race(RaceDataSource raceData, MockOutput mockOutput) {
|
public Race(RaceDataSource raceData, MockOutput mockOutput) {
|
||||||
this.startingBoats = FXCollections.observableArrayList(raceData.getBoats());
|
this.startingBoats = FXCollections.observableArrayList(raceData.getBoats());
|
||||||
@@ -48,10 +50,30 @@ public class Race implements Runnable {
|
|||||||
* Runnable for the thread.
|
* Runnable for the thread.
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
|
initialiseWindDir();
|
||||||
initialiseBoats();
|
initialiseBoats();
|
||||||
countdownTimer.start();
|
countdownTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void initialiseWindDir(){
|
||||||
|
windDir = new Random().nextInt(65535+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void changeWindDir(){
|
||||||
|
int r = new Random().nextInt(changeWind)+1;
|
||||||
|
if(r==1){
|
||||||
|
windDir+=100;
|
||||||
|
} else if (r==2){
|
||||||
|
windDir-=100;
|
||||||
|
}
|
||||||
|
if (windDir > 65535){
|
||||||
|
windDir -= 65535;
|
||||||
|
}
|
||||||
|
if (windDir < 0){
|
||||||
|
windDir += 65535;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the marker boats through mock output
|
* Parse the marker boats through mock output
|
||||||
*/
|
*/
|
||||||
@@ -80,7 +102,7 @@ public class Race implements Runnable {
|
|||||||
raceTimer.start();
|
raceTimer.start();
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
changeWindDir();
|
||||||
ArrayList<BoatStatus> boatStatuses = new ArrayList<>();
|
ArrayList<BoatStatus> boatStatuses = new ArrayList<>();
|
||||||
for (Boat boat : startingBoats) {
|
for (Boat boat : startingBoats) {
|
||||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(),
|
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(),
|
||||||
@@ -90,7 +112,7 @@ public class Race implements Runnable {
|
|||||||
parseMarks();
|
parseMarks();
|
||||||
|
|
||||||
int raceStatusNumber = timeLeft <= 60000 / scaleFactor && timeLeft > 0? 2 : 1;
|
int raceStatusNumber = timeLeft <= 60000 / scaleFactor && timeLeft > 0? 2 : 1;
|
||||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, raceStatusNumber, startTime, 0, 2300, 1, boatStatuses);
|
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, raceStatusNumber, startTime, windDir, 2300, 1, boatStatuses);
|
||||||
mockOutput.parseRaceStatus(raceStatus);
|
mockOutput.parseRaceStatus(raceStatus);
|
||||||
|
|
||||||
currentTime = System.currentTimeMillis();
|
currentTime = System.currentTimeMillis();
|
||||||
@@ -132,9 +154,10 @@ public class Race implements Runnable {
|
|||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
changeWindDir();
|
||||||
parseMarks();
|
parseMarks();
|
||||||
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
||||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 3, startTime, 0, 2300, 2, boatStatuses);
|
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 3, startTime, windDir, 2300, 2, boatStatuses);
|
||||||
mockOutput.parseRaceStatus(raceStatus);
|
mockOutput.parseRaceStatus(raceStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,6 +299,22 @@ public class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setWindDir(int wind){
|
||||||
|
if (wind>=0 && wind<=65535){
|
||||||
|
windDir = wind;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setChangeWind(int changeVal){
|
||||||
|
if (changeVal>=0){
|
||||||
|
changeWind = changeVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getWind(){
|
||||||
|
return windDir;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean doNotFinish() {
|
protected boolean doNotFinish() {
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
return rand.nextInt(100) < dnfChance;
|
return rand.nextInt(100) < dnfChance;
|
||||||
|
|||||||
@@ -222,7 +222,6 @@ public class RaceTest{
|
|||||||
BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml");
|
BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml");
|
||||||
RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||||
Race testRace = new Race(raceDataSource, mockOutput);
|
Race testRace = new Race(raceDataSource, mockOutput);
|
||||||
|
|
||||||
testRace.setDnfChance(0);
|
testRace.setDnfChance(0);
|
||||||
assertFalse(testRace.doNotFinish());
|
assertFalse(testRace.doNotFinish());
|
||||||
|
|
||||||
@@ -289,7 +288,24 @@ public class RaceTest{
|
|||||||
testBoat.setCurrentPosition(ORIGIN.getAverageGPSCoordinate());
|
testBoat.setCurrentPosition(ORIGIN.getAverageGPSCoordinate());
|
||||||
testRace.updatePosition(testBoat, 100);
|
testRace.updatePosition(testBoat, 100);
|
||||||
assertFalse(testBoat.getCurrentPosition() == ORIGIN.getAverageGPSCoordinate());
|
assertFalse(testBoat.getCurrentPosition() == ORIGIN.getAverageGPSCoordinate());
|
||||||
|
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
@Test
|
||||||
|
public void windDirectionCorrectValues(){
|
||||||
|
try {
|
||||||
|
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||||
|
BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml");
|
||||||
|
RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||||
|
Race testRace = new Race(raceDataSource, mockOutput);
|
||||||
|
testRace.setChangeWind(1);
|
||||||
|
testRace.setWindDir(65535);
|
||||||
|
testRace.changeWindDir();
|
||||||
|
assertEquals(100, testRace.getWind());
|
||||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail();
|
fail();
|
||||||
|
|||||||
Reference in New Issue
Block a user