Lunar Lander

+- HP Forums (http://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Lunar Lander (/thread-7615.html)



Lunar Lander - Gene222 - 01-17-2017 12:51 AM

Lunar Lander Simulation game, 1 dimensional, no graphics.

The lunar lander is 500 ft above the moon with a downward velocity of 50 ft/s and has 120 units of fuel. The height, velocity, and remaining fuel are displayed. The program will pause for up to 60 seconds. Enter the number of units of fuel you wish to burn during the next second, then press the Enter key. The new height, velocity and remaining fuel are displayed. The maximum amount of fuel you can burn at one time is 30 units. For more instructions, view the program INFO on the HP Prime.

The program was adapted from the Rocket program in Basic Computer Games, MicroComputer Edition, 1978 by David H. Ahl. The Rocket program was written by Eric Peters at DEC. A copy of the original program is attached [EDIT] in PDF format. A JPEG of the original program is also attached in a ZIP file. The Rocket program is a simpler version of the very first lunar lander program that was written by Jim Storer in 1969, while he was a high school student. Storer’s program, which is also included in the Basic Computer Games book, can be viewed at this post
http://www.hpmuseum.org/forum/post-41342.html

The original program was written as an interactive program, where the program prints the height, velocity, and other information, and pauses for the user to type in the amount of fuel to burn. If the HP Prime program used the Print terminal, you would not be able to display the instrument panel, pause the program and input the fuel burn. If the HP Prime program used the G0 graphic screen to display the instrument panel and the INPUT command to enter the fuel burn, the program would have to constantly flip flop between the graphic screen and input screen. So, a routine was used to enter the fuel burn while still displaying the G0 graphic screen. The routine used a FOR loop, KeyNum:=WAIT(), and IF keynum=47 THEN statements. This allowed numbers (text format) to be displayed and entered on the G0 graphic screen.

[ADDED 1/19/16]

The original Rocket program printed a plot of the distance from the lander to the ground. This distance plot was replaced with an altimeter gage.

The Rocket program used a lot of GOTO and IF THEN GOTO statements, making the program difficult to understand. The HP Prime language does not have a GOTO statement, so the Rocket program was rewritten to get rid of the GOTO statements.

For those learning to program the HP Prime, the following process was used to rewrite the loops and GOTO statements. The program was copied to a word processor, and the variable names were replaced with names that explained what the variables were. The GOTO statements were highlighted in yellow, and the loops were identified, as shown on Attachment 1.

The first loop is used to print the Time, Height, Velocity, Fuel, and Distance Plot. The program stops, and the user inputs the amount of fuel to burn. The loop takes the fuel burn amount and updates the Time, Height, Velocity, and Fuel amounts. The loop then repeats itself, if there is fuel remaining. The program breaks from the loop, if the height is less than or equal to zero, meaning the vehicle has landed or crashed. Basically, the first loop is used to allow the user to input a fuel burn, while the vehicle is still in the air.

The second loop is used when the vehicle runs out of fuel and is still above ground. Here, the user cannot input a fuel burn. The program prints an “out of fuel” message, and the 2nd loop prints the Time, Height, Velocity, Fuel, and Distance Plot. Using a fuel burn of zero, the loop updates the Time, Height, Velocity and Fuel amounts, and then repeats itself in increments of one second as long as the vehicle is still in the air.

The two loops overlap each other, where each loop shared some of the same code, as shown in Attachment 1. These two loops were separated, where the shared code was duplicated in each loop. The loop controls statements were changed to HP Prime loop statements. Every entrance into and out of each loop was checked to make sure the program flowed the same as the original program. Finally, each GOTO statement was eliminated by rearranging the code or by using an IF or IF ELSE statement in HP Prime format, while making sure the program flowed the same as the original program. The rearranged and modified code of the original program is shown in Attachment 2. This was used as a guide to write the final code in HP Prime language.