Lunar Lander bug?

06102014, 09:02 PM
Post: #1




Lunar Lander bug?
I was playing with the lunar lander game on my 29C and took a look at the source code. I can't figure out the terminal velocity calculation and I was wondering if someone could walk me through it. The program is here.
Lines 4650 indicate that a burn b accelerates the craft by a=2b5. This indicates that gravity is 5. It's also easy to deduce that each burn lasts 1 second. So when you burn the last of the fuel, what is the crash velocity? To figure this out, recognize that you get a 1 second burn consisting of the all the fuel (a=2b5), followed by a free fall that ends in a crash landing (a=5). Using the equations provided: \begin{equation}a_0=2b5\\ v_1 = v_0+a_0t = v_0+2b5\\ x_1 = x_0+v_0t+\frac{1}{2}a_0t^2 = x_0+v_0+b2.5\\ v_f^2 = v_1^2 + 2a_1(x_fx_1) = v_1^2 + 2a_1(0x_1) = v_1^2+2*(5)*(x_1)\\ v_f = \sqrt{v_1^2+10x_1}\end{equation} Lines 4144 compare the burn amount to the remaining fuel. If you're burning the last of the fuel it goes to label 6 at line 68. Lines 6974 add b2.5 to x Lines 7577 add 2b5 to v Lines 7886 compute vf from x I don't understand lines 6974. It seems to me that it should subtract v from x also. Am I missing something or is this a bug? Thanks, Dave 

06112014, 07:28 AM
Post: #2




RE: Lunar Lander bug?
(06102014 09:02 PM)David Hayden Wrote: I don't understand lines 6974. It seems to me that it should subtract v from x also. Am I missing something or is this a bug? But in some cases that might turn out negative and then you have a problem when taking the square root in line 85. You could change the program that in lines 4144 you just use the remaining fuel if the entry was bigger than that (no branch to LBL 6), calculate the new values, check whether we crashed and check whether we still have fuel. Only then loop back. Otherwise calculate the final crash velocity. With this approach the redundant calculations after LBL 6 could be avoided. Cheers Thomas PS: The LBL 9 in line 40 could probably be removed. 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)