Post Reply 
TI-57 Lunar Lander ?
06-04-2022, 06:22 PM (This post was last modified: 06-04-2022 08:19 PM by pauln.)
Post: #21
RE: TI-57 Lunar Lander ?
I have been looking for a Lunar Lander for TI-57/RCL-57 and I came across this older thread. I ended up writing my own version which I list here for anyone interested.

IMO, it has a few advantages over the one in "L'Ordinateur de Poche":
  • It displays the sign of the velocity, making clear whether the rocket is descending or not
  • There is no need to enter the fix mode
  • It gives a clear indication that the game has ended (display blinking)
  • It computes velocity and altitude every second, looking for landing or a crash, instead of doing so only every 10 seconds

Instructions:
  1. Key in the program
  2. Enter initial velocity: 100 STO 1
  3. Enter initial altitude: 2500 STO 2
  4. Enter initial fuel: 100 STO 3
  5. RST R/S
    You should see "100" (fuel) followed by "100.2500" (velocity.altitude).
  6. 'N' R/S
    where 'N' (N integer >= 0) is the number of gallons to consume in the next 4 seconds.
    You should see "fuel" and, after a pause, "velocity.altitude"
  7. Repeat Step 6 until the display blinks
    if >= 0, you landed safely
    if < 0, you crashed

If you want to see your final velocity, press RCL 1.

Code:

# Displays the current state.
RCL 3 INV Fix Pause                    # Fuel 
RCL 1 x:t 1 +/- INV x>=t +/-           # Compute sign of velocity
x
RCL 2 / 4 INV log + RCL 1 = Fix 4      # velocity.altitude
R/S

# Updates the fuel available
STO 4                                  # Number of gallons for the next 4 seconds
x:t RCL 3 INV x>=t STO 4               # Ensure it doesn't exceed quantity of fuel left
RCL 4 INV SUM 3                        # Update fuel

# Loops 4 times (4 seconds)
5 STO 0 Lbl 0 INV Dsz RST

# Updates the altitude and velocity after 1 second
RCL 1 INV SUM 2                        # Altitude
5 SUM 1 RCL 4 INV SUM 1                # Velocity

# Determines what happened in the last second
RCL 2 C.t INV x>=t GTO 7               # Crash: note the non existent label 7
6 x:t
RCL 1 |x| + RCL 2 = x>=t GTO 0         # Not landing: loop back

# Safe landing: if |velocity| + altitude <= 5, the display will blink (>= 0) since GTO 0 is at the last step (49)
Find all posts by this user
Quote this message in a reply
06-12-2022, 07:00 PM (This post was last modified: 06-12-2022 07:01 PM by Thomas Klemm.)
Post: #22
RE: TI-57 Lunar Lander ?
(06-04-2022 06:22 PM)pauln Wrote:  
Code:
# Loops 4 times (4 seconds)
5 STO 0 Lbl 0 INV Dsz RST

I was not sure whether to trust the comment or the code.
Therefore I changed it to:
Code:
# Loops 4 times (4 seconds)
4 STO 0 Lbl 0 INV Dsz RST

With this I came up with the following solution to a safe landing:

100.
100.2500


5 R/S

95.
100.2200


5 R/S

90.
100.1900


5 R/S

85.
100.1600


5 R/S

80.
100.1300


5 R/S

75.
100.1000


10 R/S

65.
85.0715


10 R/S

55.
70.0475


10 R/S

45.
55.0280


10 R/S

35.
40.0130


10 R/S

25.
25.0025


25 R/S

»5.0000«

That was surprisingly fun to figure out.



Here's a mostly verbatim translation of the program for the HP-42S:
Code:
00 { 92-Byte Prgm }
01▸LBL "LUNAR"
02 2500
03 STO 02
04 100
05 STO 01
06 STO 03
07▸LBL 01
08 "Fuel: "
09 ARCL 03
10 ├" Vel: "
11 ARCL 01
12 ├"[LF]Alt: "
13 ARCL 02
14 PROMPT
15 RCL 03
16 X>Y?
17 X<>Y
18 STO 04
19 STO- 03
20 4
21 STO 00
22▸LBL 00
23 DSE 00
24 FS? 00 # assume it is clear
25 GTO 01
26 RCL 01
27 STO- 02
28 5
29 STO+ 01
30 RCL 04
31 STO- 01
32 RCL 02
33 X<0?
34 GTO 07
35 6
36 RCL 01
37 ABS
38 RCL 02
39 +
40 X≥Y?
41 GTO 00
42 END
Find all posts by this user
Quote this message in a reply
06-12-2022, 07:13 PM
Post: #23
RE: TI-57 Lunar Lander ?
(06-12-2022 07:00 PM)Thomas Klemm Wrote:  I was not sure whether to trust the comment or the code.

Well, I should have read this code more thoroughly.
There's no reason to change it.
Find all posts by this user
Quote this message in a reply
06-12-2022, 07:38 PM
Post: #24
RE: TI-57 Lunar Lander ?
Nice!

As you noticed later, by changing the value from 5 to 4, you are only descending for 3 seconds. On the other hand, with that change, the game becomes quite a bit harder and arguably more interesting for the experienced Lunar Lander player.
Find all posts by this user
Quote this message in a reply
Post Reply 




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