diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index dde6fa0..e2222bb 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -6,6 +6,7 @@
+
diff --git a/src/main/java/BurnDataStream.java b/src/main/java/BurnDataStream.java
index 051be0a..07d28ff 100644
--- a/src/main/java/BurnDataStream.java
+++ b/src/main/java/BurnDataStream.java
@@ -3,7 +3,8 @@ public class BurnDataStream implements BurnStream {
// change them to see if you can get the lander to make a soft landing.
// burns are between 0 and 200. This burn array usually crashes.
- int burnArray[] = {100, 100, 200, 200, 100, 100, 0, 0, 200, 100, 100, 0, 0, 0, 0};
+ //int burnArray[] = {100, 100, 200, 200, 100, 100, 0, 0, 200, 100, 100, 0, 0, 0, 0};
+ int burnArray[] = {100, 100, 200, 200, 100, 100, 0, 0, 200, 100, 100, 0, 200, 200, 100};
int burnIdx = -1;
public BurnDataStream() { }
diff --git a/src/main/java/BurnInputStream.java b/src/main/java/BurnInputStream.java
index c78b6c6..bdb760d 100644
--- a/src/main/java/BurnInputStream.java
+++ b/src/main/java/BurnInputStream.java
@@ -10,10 +10,14 @@ public int getNextBurn(DescentEvent status) {
while (true) {
try {
int burn = Integer.parseInt(tokens[0]);
- return burn;
+ if(burn >= 0 && burn <= 200) {
+ return burn;
+ }
+ System.out.println("Must Enter a Number (0-200)");
} catch (NumberFormatException e) {
System.err.println("Must Enter a Number (0-200)");
}
+ tokens = scanner.nextLine().split(" ");
}
}
return 0;
diff --git a/src/main/java/DescentEvent.java b/src/main/java/DescentEvent.java
index 2add30f..e39b478 100644
--- a/src/main/java/DescentEvent.java
+++ b/src/main/java/DescentEvent.java
@@ -1,4 +1,4 @@
-public class DescentEvent {
+public class DescentEvent {
int Seconds = 0;
int Velocity = 0;
int Fuel = 0;
@@ -10,6 +10,7 @@ public DescentEvent(int t, int sp, int f, int h, int st) {
this.Velocity = sp;
this.Fuel = f;
this.Altitude = h;
+ this.Status = st;
}
public int getVelocity() {
diff --git a/src/main/java/MainClass.java b/src/main/java/MainClass.java
new file mode 100644
index 0000000..51299db
--- /dev/null
+++ b/src/main/java/MainClass.java
@@ -0,0 +1,13 @@
+public class MainClass {
+
+ public static void main(String[] args) {
+ // create a new Simulation object with a random starting altitude
+ Simulation game = new Simulation(new Vehicle(Simulation.randomaltitude()));
+ // create a new BurnInputStream
+ BurnInputStream burnSource = new BurnInputStream();
+ // pass the new BurnInputStream to the runSimulation method
+ game.runSimulation(burnSource);
+
+ }
+
+}
diff --git a/src/main/java/OnBoardComputer.java b/src/main/java/OnBoardComputer.java
index b219803..8b43971 100644
--- a/src/main/java/OnBoardComputer.java
+++ b/src/main/java/OnBoardComputer.java
@@ -3,9 +3,66 @@ public class OnBoardComputer implements BurnStream {
@Override
public int getNextBurn(DescentEvent status) {
int burn = 0;
-
+ int nextAlt = nextAltWithVelocity(status.getAltitude(), status.getVelocity(), burn);
+ int alt = status.getAltitude();
+ int fuel = status.Fuel;
+ int vel = status.getVelocity();
+ int stat = status.getStatus();
+ boolean done = false;
+
+ while(!done){
+ if(alt < 400 && vel <200){
+ if(alt < 200 && vel < 50){
+ if(alt < 100 && vel < 25){
+ if(alt < 15 && vel < 10){
+ burn = targetVelocity(status.getVelocity(),2);
+ System.out.println(burn); /*hack!*/
+ return burn;
+ }
+ burn = targetVelocity(status.getVelocity(), 9);
+ System.out.println(burn); /*hack!*/
+ return burn;
+ }
+ burn = targetVelocity(status.getVelocity(), 24);
+ System.out.println(burn); /*hack!*/
+ return burn;
+ }
+ burn = targetVelocity(status.getVelocity(), 49);;
+ System.out.println(burn); /*hack!*/
+ return burn;
+ }
+
+ if(burn == 200){
+ System.out.println(burn); /*hack!*/
+ return burn;
+ }
+ if(nextVelocityWithBurn(status.Velocity, burn) < calculateMaxVel(nextAlt)){
+ System.out.println(burn); /*hack!*/
+ return burn;
+ }
+ burn += 50;
+ }
+
System.out.println(burn); /*hack!*/
return burn;
}
+
+ public int calculateMaxVel(int altitude) {
+ return (int) Math.sqrt(200* altitude);
+ }
+
+
+ public int nextAltWithVelocity(int altitude, int velocity, int burn) {
+ return altitude - (velocity + 100) + burn;
+ }
+
+ public int nextVelocityWithBurn(int velocity, int burn) {
+ return velocity + 100 - burn;
+ }
+
+ public int targetVelocity(int velocityCurrent, int velocityTarget){
+ return velocityCurrent+100-velocityTarget;
+ }
+
}
diff --git a/src/main/java/Simulation.java b/src/main/java/Simulation.java
index 482634f..a31eab6 100644
--- a/src/main/java/Simulation.java
+++ b/src/main/java/Simulation.java
@@ -73,9 +73,15 @@ public int runSimulation(BurnStream burnSource) {
}
public static void main(String[] args) {
- // create a new Simulation object with a random starting altitude
+
+ Simulation game = new Simulation(new Vehicle(50000));
+ //Simulation game = new Simulation(new Vehicle(Simulation.randomaltitude()));
// create a new BurnInputStream
+ //BurnStream burnSource = new BurnInputStream();
+ OnBoardComputer burnSource = new OnBoardComputer();
// pass the new BurnInputStream to the runSimulation method
+ game.runSimulation(burnSource);
+
}
}
diff --git a/src/main/java/Vehicle.java b/src/main/java/Vehicle.java
index e67f2c0..166622f 100644
--- a/src/main/java/Vehicle.java
+++ b/src/main/java/Vehicle.java
@@ -2,6 +2,8 @@ public class Vehicle {
public Vehicle(int InitialAltitude) {
// initialize the altitude AND previous altitude to initialAltitude
+ this.Altitude = InitialAltitude;
+ this.PrevAltitude = InitialAltitude;
}
int Gravity = 100;
@@ -54,30 +56,42 @@ public String checkFinalStatus() {
public int computeDeltaV() {
// return velocity + gravity - burn amount
- return 0;
+ return this.Velocity + Gravity - Burn;
}
public void adjustForBurn(int burnAmount) {
// set burn to burnamount requested
+ Burn = burnAmount;
// save previousAltitude with current Altitude
+ PrevAltitude = this.Altitude;
// set new velocity to result of computeDeltaV function.
+ Velocity = computeDeltaV();
// subtract speed from Altitude
+ Altitude -= Velocity;
// subtract burn amount fuel used from tank
+ Fuel -= Burn;
}
public boolean stillFlying() {
// return true if altitude is positive
+ if(Altitude>0){
+ return true;
+ }
return false;
}
public boolean outOfFuel() {
// return true if fuel is less than or equal to zero
- return true;
+ if(Fuel <= 0){
+ return true;
+ }
+ return false;
}
public DescentEvent getStatus(int tick) {
// create a return a new DescentEvent object
// filled in with the state of the vehicle.
- return null;
+ DescentEvent state= new DescentEvent(tick, Velocity, Fuel, Altitude, this.Flying);
+ return state;
}
}
diff --git a/src/test/java/OnBoardComputerTest.java b/src/test/java/OnBoardComputerTest.java
new file mode 100644
index 0000000..5966ffb
--- /dev/null
+++ b/src/test/java/OnBoardComputerTest.java
@@ -0,0 +1,69 @@
+import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class OnBoardComputerTest {
+
+ @Test
+ public void calcMaxVelocityTest(){
+
+ //Given
+ int altitude = 5000;
+ int velocity = 1000;
+ int acceleration = 100;
+ OnBoardComputer jerry = new OnBoardComputer();
+
+
+ //When
+ DescentEvent stat = new DescentEvent(10, velocity, 12000, altitude, 0);
+ int actual = jerry.calculateMaxVel(stat.Altitude);
+ int expected = 1000;
+
+ //Then
+ Assert.assertEquals(expected,actual);
+
+ }
+
+ @Test
+ public void nextAlt(){
+
+ //Given
+ int altitude = 5000;
+ int velocity = 1000;
+ int acceleration = 100;
+ int burn = 200;
+ OnBoardComputer jerry = new OnBoardComputer();
+
+
+ //When
+ DescentEvent stat = new DescentEvent(10, velocity, 12000, altitude, 0);
+ int actual = jerry.nextAltWithVelocity(stat.getAltitude(), stat.getVelocity(), burn);
+ int expected = 4100;
+
+ //Then
+ Assert.assertEquals(expected,actual);
+
+ }
+
+ @Test
+ public void nextVelocity(){
+
+ //Given
+ int altitude = 5000;
+ int velocity = 1000;
+ int acceleration = 100;
+ int burn = 200;
+ OnBoardComputer jerry = new OnBoardComputer();
+
+
+ //When
+ DescentEvent stat = new DescentEvent(10, velocity, 12000, altitude, 0);
+ int actual = jerry.nextVelocityWithBurn(stat.getVelocity(), burn);
+ int expected = 900;
+
+ //Then
+ Assert.assertEquals(expected,actual);
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/SimulationTest.java b/src/test/java/SimulationTest.java
index 8fd05b4..ae7093f 100644
--- a/src/test/java/SimulationTest.java
+++ b/src/test/java/SimulationTest.java
@@ -14,16 +14,18 @@ public void runSimulationLanding() {
BurnStream burnSource = new BurnDataStream(burns);
Simulation game = new Simulation(new Vehicle(5000));
int okay = game.runSimulation(burnSource);
- Assert.assertEquals(okay, Vehicle.SUCCESS);
+ Assert.assertEquals(Vehicle.SUCCESS, okay );
}
@Test
public void runSimulationCrash() {
- int[] burns = {0,0,0,0,0};
+ //int[] burns = {0,0,0,0,0};
+ int[] burns = {200,200,200,200,200,200,100,200,200,200,150,125,120,100,100,100,104,100,100,100,100};
+ //values that passed ^^
BurnStream burnSource = new BurnDataStream(burns);
Simulation game = new Simulation(new Vehicle(5000));
int okay = game.runSimulation(burnSource);
- Assert.assertEquals(Vehicle.CRASHED, okay);
+ Assert.assertEquals(Vehicle.DEAD, okay);
}
@Test