Post Reply 
Rocket Game - from 101 BASIC Computer Games
08-16-2015, 04:39 PM (This post was last modified: 08-19-2015 01:36 AM by smp.)
Post: #1
Rocket Game - from 101 BASIC Computer Games
I am attempting to convert the old Rocket BASIC game (from 101 BASIC Computer Games by Digital Equipment Corporation) to run on my HP Prime calculator. I'm doing this as one of my exercises in learning to program on the HP Prime, and also to end up with one of the vintage games I love running on my calculator.

Here's the original BASIC code:
Code:

2 PRINT "THIS IS A COMPUTER SIMULATION OF AN APOLLO LUNAR"
3 PRINT "LANDING CAPSULE, "\PRINT\PRINT
4 PRINT "THE ON-BOARD COMPUTER HAS FAILED (IT WASN'T MADE BY"
5 PRINT "DIGITAL) SO YOU HAVE TO LAND THE CAPSULE MANUALLY"
6 PRINT\PRINT "SET BURN RATE OF RETRO ROCKETS TO ANY VALUE BETWEEN"
7 PRINT "0 (FREE FALL) AND 200 (MAXIMUM BURN) POUNDS PER SECOND"
8 PRINT "SET NEW BURN RATE EVERY 10 SECONDS. "\PRINT
9 PRINT "CAPSULE WEIGHT 32,500 LBS, FUEL WEIGHTT 16,500 LBS"
19 PRINT\PRINT\PRINT "GOOD LUCK!!!"
11 L=0
13 PRINT\PRINT "SEC", "MI + FT", "MPH", "LB FUEL", "BURN RATE"\PRINT
15 A=120\V=1\M=33000\N=16500\G=1E-3\Z=1.8
21 PRINT L,INT(A); INT(5280*(A-INT(A))),3600*V,M-N,\INPUT K\T=10
31 IF M-N<.001 THEN 41\IF T<.001 THEN 21\S=T\IF M>N+S*K THEN 35
32 S=(M-N)/K
35 GOSUB 91\IF I<=0 THEN 71\IF V<=0 THEN 38\lF J<0 THEN 81
38 GOSUB 61\GOTO 31
41 PRINT "FUEL OUT AT"L "SEC "\S=(-V+SQR(V*V+2*A*G))/G\V=V+G*S\L=L+S
51 W=3600*V\PRINT"ON MOON AT"L"SEC - IMPACT VELOCITY" W "MPH"
52 IF W>1.2 THEN 53\PRINT "PERFECT LANDING! (LUCKY)"\GOTO 95
53 IF W>10 THEN 56\PRINT "GOOD LANDING (COULD BE BETTER)"\GOTO 95
56 IF W>60 THEN 58\PRINT "CRAFT DAMAGE... YOU'RE STRANDED HERE UNTIL"
57 PRINT "A RESCUE PARTY ARRIVES, HOPE YOU HAVE ENOUGH OXYGEN!"\GOTO 95
58 PRINT "SORRY, BUT THERE WERE NO SURVIVORS... YOU BLEW IT!"
59 PRINT "IN FACT, YOU BLASTED A NEW LUNAR CRATER"W*.2777"FT DEEP"
60 GOTO 95
61 L=L+S\T=T-S\M=M-S*K\A=I\V=J\RETURN
71 IF S<5E-3 THEN 51\D=V+SQR(V*V+2*A*(G-Z*K/M)\S=2*A/D
73 GOSUB 91\GOSUB 61\GOTO 71
81 W=(1-M*G/(Z*K))/2\S=M*V/(Z*K*(W+SQR(W*W+V/Z)))+.05\GOSUB 91
83 IF I<=0 THEN 71\GOSUB 61\IF J>0 THEN 31\IF V>0 THEN 81\GOTO 31
91 Q=S*K/M\J=V+G*S+Z*(-Q-Q*Q/2-Q^3/3-Q^4/4-Q^5/5)
94 I=A-G*S*S/2-V*S+Z*S*(Q/2+Q^2/6+Q^3/12+Q^4/20+Q^5/30)\RETURN
95 PRINT\PRINT\PRINT\PRINT "TRY AGAIN??"\GOTO 6
99 END

If you peruse the original code, you will see the quandary that I'm in. It is peppered with GOTOs and jumps as the result of IF THEN statements. Disentangling this has become somewhat of a mission for me.

I have figured out the way I want to do my version of this program. It is a simple falling body in a vacuum problem, so there are two conditions: Are you still above the ground? and Do you have any fuel left for your retro rockets? You must manage your descent using different rates of fuel consumption in order to arrive at the ground with fuel left, and pretty near zero downward velocity.

So I have the following code working for a falling body in a vacuum:
Code:

EXPORT Lander()
BEGIN
  PRINT();
  L:=0;       // ELAPSED TIME
  T:=10;      // SEC PER INTERVAL
  A:=120;     // MI
  V:=1;       // MI/S
  M:=33000;   // LB
  N:=16500;   // LB
  G:=1.6249;  // MOON G IN M/S^2

  PRINT("SEC : " +"MI+FT : " +"MPH : " +"LB_FUEL : " +"RATE : ");

  A:=A*1609.344; // CONVERT ALT TO METERS
  V:=V*1609.344; // CONVERT VEL TO M/S

  WHILE A>0 DO  // while not yet landed
    PRINT(L +" : " +IP(A/1609.344) +"+" +IP(5280*FP(A/1609.344)) +" : " +IP((3600*(V/1609.344))) +" : " +(M-N) +" : ");
    INPUT(R);   // GET BURN RATE

    IF M-N>R*T THEN  // if fuel left
      
      M:=M-(R*T);
    END;

    D:=(V*T+0.5*G*T^2);
    A:=A-D;
    V:=(V+G*T);
    L:=L+T;

  END;

  PRINT(L +" : " +IP(A/1609.344) +"+" +IP(5280*FP(A/1609.344)) +" : " +IP((3600*(V/1609.344))) +" : " +(M-N) +" : ");
END;

This code I have works perfectly like the sample run in the original book for the time that there is 0 as the input for the burn rate, so I figure that I have the falling body in a vacuum code in good shape.

Where I have been struggling for the past week, is to understand what the original author is doing to form the opposing vector made by the entry of the burn rate. It looks to me like the original code converts everything to increments of time somehow and computes distance and velocity from that? I'm pretty much stumped at this point.

If anyone cares to take a look at the code and offer me any suggestions on how to implement the retro rocket burn rate to slow the descent, I would greatly appreciate any thoughts you may have.

Thanks in advance!

smp
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Rocket Game - from 101 BASIC Computer Games - smp - 08-16-2015 04:39 PM



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