Post Reply 
Rocket Game - from 101 BASIC Computer Games
08-18-2015, 02:39 PM
Post: #6
RE: Rocket Game - from 101 BASIC Computer Games
(08-16-2015 04:39 PM)smp Wrote:  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 30\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 93
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

Would the version in the microcomputer edition of 101 BASIC Games help? This was written by Ahl after the original DEC version. The programs were converted from DEC Basic Plus to run in 8K Altair (Microsoft BASIC)

Code:

10 PRINT TAB(30); "ROCKET"
20 PRINT TAB(15); "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
30 PRINT: PRINT: PRINT
70 PRINT "LUNAR LANDING SIMULATION"
80 PRINT "----- ------- ----------": PRINT
100 INPUT "DO YOU WANT INSTRUCTIONS (YES OR NO)"; A$
110 IF A$ = "NO" THEN 390
160 PRINT
200 PRINT "YOU ARE LANDING ON THE MOON AND AND HAVE TAKEN OVER MANUAL"
210 PRINT "CONTROL 1000 FEET ABOVE A GOOD LANDING SPOT. YOU HAVE A DOWN-"
220 PRINT "WARD VELOCITY OF 50 FEET/SEC. 150 UNITS OF FUEL REMAIN."
225 PRINT
230 PRINT "HERE ARE THE RULES THAT GOVERN YOUR APOLLO SPACE-CRAFT:": PRINT
240 PRINT "(1) AFTER EACH SECOND THE HEIGHT, VELOCITY, AND REMAINING FUEL"
250 PRINT "    WILL BE REPORTED VIA DIGBY YOUR ON-BOARD COMPUTER."
260 PRINT "(2) AFTER THE REPORT A '?' WILL APPEAR. ENTER THE NUMBER"
270 PRINT "    OF UNITS OF FUEL YOU WISH TO BURN DURING THE NEXT"
280 PRINT "    SECOND. EACH UNIT OF FUEL WILL SLOW YOUR DESCENT BY"
290 PRINT "    1 FOOT/SEC."
310 PRINT "(3) THE MAXIMUM THRUST OF YOUR ENGINE IS 30 FEET/SEC/SEC"
320 PRINT "    OR 30 UNITS OF FUEL PER SECOND."
330 PRINT "(4) WHEN YOU CONTACT THE LUNAR SURFACE. YOUR DESCENT ENGINE"
340 PRINT "    WILL AUTOMATICALLY SHUT DOWN AND YOU WILL BE GIVEN A"
350 PRINT "    REPORT OF YOUR LANDING SPEED AND REMAINING FUEL."
360 PRINT "(5) IF YOU RUN OUT OF FUEL THE '?' WILL NO LONGER APPEAR"
370 PRINT "    BUT YOUR SECOND BY SECOND REPORT WILL CONTINUE UNTIL"
380 PRINT "    YOU CONTACT THE LUNAR SURFACE.": PRINT
390 PRINT "BEGINNING LANDING PROCEDURE..........": PRINT
400 PRINT "G O O D  L U C K ! ! !"
420 PRINT: PRINT
430 PRINT "SEC  FEET      SPEED     FUEL     PLOT OF DISTANCE"
450 PRINT
455 T = 0: H = 1000: V = 50: F = 150
490 PRINT T; TAB(6); H; TAB(16); V; TAB(26); F; TAB(35); "I"; TAB(H / 15); "*"
500 INPUT B
510 IF B < 0 THEN 650
520 IF B > 30 THEN B = 30
530 IF B > F THEN B = F
540 V1 = V - B + 5
560 F = F - B
570 H = H - .5 * (V + V1)
580 IF H <= 0 THEN 670
590 T = T + 1
600 V = V1
610 IF F > 0 THEN 490
615 IF B = 0 THEN 640
620 PRINT "**** OUT OF FUEL ****"
640 PRINT T; TAB(4); H; TAB(12); V; TAB(20); F; TAB(29); "I"; TAB(H / 12 + 29); "*"
650 B = 0
660 GOTO 540
670 PRINT "***** CONTACT *****"
680 H = H + .5 * (V1 + V)
690 IF B = 5 THEN 720
700 D = (-V + SQR(V * V + H * (10 - 2 * B))) / (5 - B)
710 GOTO 730
720 D = H / V
730 V1 = V + (5 - B) * D
760 PRINT "TOUCHDOWN AT"; T + D; "SECONDS."
770 PRINT "LANDING VELOCITY="; V1; "FEET/SEC."
780 PRINT F; "UNITS OF FUEL REMAINING."
790 IF V1 <> 0 THEN 810
800 PRINT "CONGRATULATIONS! A PERFECT LANDING!!"
805 PRINT "YOUR LICENSE WILL BE RENEWED.......LATER."
810 IF ABS(V1) < 2 THEN 840
820 PRINT "***** SORRY, BUT YOU BLEW IT!!!!"
830 PRINT "APPROPRIATE CONDOLENCES WILL BE SENT TO YOUR NEXT OF KIN."
840 PRINT: PRINT: PRINT
850 INPUT "ANOTHER MISSION"; A$
860 IF A$ = "YES" THEN 390
870 PRINT: PRINT "CONTROL OUT.": PRINT
999 END

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Rocket Game - from 101 BASIC Computer Games - toml_12953 - 08-18-2015 02:39 PM



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