Back to General discussions forum
When I use the provided test application and then enter the same values in my program, I get nearly the same results. When I then submit my code for verification, I get considerably different answers.
Hi!
link to your code for convenience
I'm not quite sure, but it seems that your main loop:
public void land(int[] rates) {
for (int rate : rates) {
burn(rate);
}
}
Does not take care of landing the craft if the fuel ends before touchdown - isn't it so?
After the fuel is ended the further settings should be ignored. If after proceeding through all the sequence the rocket still is not on the surface, continue calculation as it is in free fall.
I'm sorry if this part of problem statement looks vague...
float deltaFuel = 0;
if (fuelMass > 0) {
deltaFuel = rate * dt;
if(fuelMass - deltaFuel < 0) {
deltaFuel = fuelMass;
}
}
float deltaV = EXHAUST_SPEED * deltaFuel / (emptyMass + fuelMass);
fuelMass -= deltaFuel;
if(height >= 0) {
velocity = velocity + (getGravity() * dt) - deltaV;
} else {
velocity = 0;
}
If there is no remaining fuel, deltaFuel is 0, making deltaV 0. As a result it becomes:
velocity = velocity + (getGravity() * dt) - 0f;
Which only takes gravity into account.
>Which only takes gravity into account.
This sounds correct, yes - but I do not see how your formula allows to calculate the change of speed during free fall.
Say, if rates
contains only one value, we burn it very soon - and then we still need to
calculate many iterations of free fall (and with changing gravity).
However it looks like your loops will stop after processing rates
is completed.
Or may be I'm misunderstanding something?
I see my error. For some reason I had interpreted the answer as the velocity of the ship after the last attempt to burn fuel. I have since added some logic to allow it to fall until it reaches the surface. I appreciate the help.
Lubecki - Your approach looks very similar to mine; great minds think alike :)
-- Christopher P. Matthews
Расход топлива секундный в условие добавьте, пожалуйста.
Вопрос снят. "Rate" в условие упомянуть бы, и единицами обозначить. А то не ясно регулировка тяги в процентах это, или регулировка дросселя в системе подаче топлива в единицах массы.