LunarBas

Source: http://vintage-basic.net/bcg/lunar.bas

10 PRINT TAB(33);"LUNAR"
20 PRINT TAB(l5);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY" 
25 PRINT
26 PRINT
27 PRINT
30 PRINT "THIS IS A COMPUTER SIMULATION OF AN APOLLO LUNAR" 
40 PRINT "LANDING CAPSULE."
41 PRINT
42 PRINT
50 PRINT "THE ON-BOARD COMPUTER HAS FAILED (IT WAS MADE BY" 
60 PRINT "XEROX) SO YOU HAVE TO LAND THE CAPSULE MANUALLY."
70 PRINT
71 PRINT "SET BURN RATE OF RETRO ROCKETS TO ANY VALUE BETWEEN" 
80 PRINT "0 (FREE FALL) AND 200 (MAXIMUM BURN) POUNDS PER SECOND." 
90 PRINT "SET NEW BURN RATE EVERY 10 SECONDS."
91 PRINT 
100 PRINT "CAPSULE WEIGHT 32,500 LBS; FUEL WEIGHT 16,500 LBS."
110 PRINT
111 PRINT
112 PRINT
113 PRINT "GOOD LUCK"
120 L=0
130 PRINT
131 PRINT "SEC","MI + FT","MPH","LB FUEL","BURN RATE"
132 PRINT 
140 A=120
141 V=1
142 M=33000
143 N=16500
144 G=1E-03
145 Z=1.8
150 PRINT L,INT(A);INT(5280*(A-INT(A))),3600*V,M-N,
151 INPUT K
152 T=10 
160 IF M-N<1E-03 THEN 240
170 IF T<1E-03 THEN 150
180 S=T
181 IF M>=N+S*K THEN 200
190 S=(M-N)/K
200 GOSUB 420
201 IF I<=O THEN 340
210 IF V<=0 THEN 230
220 IF J<0 THEN 370
230 GOSUB 330
231 GOTO 160
240 PRINT "FUEL OUT AT";L;"SECONDS"
241 S=(-V+SQR(V*V+2*A*G))/G
250 V=V+G*S
251 L=L+S
260 W=3600*V
261 PRINT "ON MOON AT";L;"SECONDS - IMPACT VELOCITY";W;"MPH" 
274 IF W<=1.2 THEN PRINT "PERFECT LANDING!"
275 GOTO 440 
280 IF W<=10 THEN PRINT "GOOD LANDING (COULD RE BETTER)"
281 GOTO 440 
282 IF W>60 THEN 300
284 PRINT "CRAFT DAMAGE... YOU'RE STRANDED HERE UNTIL A RESCUE" 
286 PRINT "PARTY ARRIVES. HOPE YOU HAVE ENOUGH OXYGEN!" 
288 GOTO 440
300 PRINT "SORRY THERE NERE NO SURVIVORS. YOU BLOW IT!"
310 PRINT "IN FACT, YOU BLASTED A NEW LUNAR CRATER";W*.227;"FEET DEEP!"
320 GOTO 440
330 L=L+S
331 T=T-S
332 M=M-S*K
333 A=I
334 V=J
335 RETURN
340 IF S<5E-03 THEN 260
350 D=V+SQR(V*V+2*A*(G-Z*K/M))
351 S=2*A/D
360 GOSUB 420
361 GOSUB 330
362 GOTO 340
370 W=(1-M*G/(Z*K))/2
371 S=M*V/(Z*K*(W+SQR(W*W+V/Z)))+.05
372 GOSUB 420
380 IF I<=0 THEN 340
390 GOSUB 330
391 IF J>0 THEN 160
400 IF V>0 THEN 370
410 GOTO 160
420 Q=S*K/M
421 J=V+G*S+Z*(-Q-Q*Q/2-Q^3/3-Q^4/4-Q^5/5)
430 I=A-G*S*S/2-V*S+Z*S*(Q/2+Q^2/6+Q^3/12+Q^4/20+Q^5/30)
431 RETURN
440 PRINT
441 PRINT
442 PRINT
443 PRINT 'TRY AGAIN??"
444 GOTO 70

Annotation

10PRINT TAB(33);"LUNAR"10-113: Title, description, instructions
20PRINT TAB(l5);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
25PRINT
26PRINT
27PRINT
30PRINT "THIS IS A COMPUTER SIMULATION OF AN APOLLO LUNAR"
40PRINT "LANDING CAPSULE."
41PRINT
42PRINT
50PRINT "THE ON-BOARD COMPUTER HAS FAILED (IT WAS MADE BY"
60PRINT "XEROX) SO YOU HAVE TO LAND THE CAPSULE MANUALLY."
70PRINT
71PRINT "SET BURN RATE OF RETRO ROCKETS TO ANY VALUE BETWEEN"
80PRINT "0 (FREE FALL) AND 200 (MAXIMUM BURN) POUNDS PER SECOND."
90PRINT "SET NEW BURN RATE EVERY 10 SECONDS."
91PRINT
100PRINT "CAPSULE WEIGHT 32,500 LBS; FUEL WEIGHT 16,500 LBS."
110PRINT
111PRINT
112PRINT
113PRINT "GOOD LUCK"
120L=0L: time (s)
130PRINT
131PRINT "SEC","MI + FT","MPH","LB FUEL","BURN RATE"Status headings
132PRINT
140A=120A: altitude (mi)
141V=1V: descent speed (mi/s)
142M=33000M: total mass (lbs)
143N=16500N: capsule mass (lbs)
144G=1E-03G: ?
145Z=1.8Z: ?
150PRINT L,INT(A);INT(5280*(A-INT(A))),3600*V,M-N,Display status
151INPUT KK: burn rate (lb/s)
152T=10T: turn length (s)
160IF M-N<1E-03 THEN 240If total mass is <= capsule mass, jump to out-of-fuel process
170IF T<1E-03 THEN 150If turn interval is < .001 s, repeat status display (does this ever happen?)
180S=TS: turn length (s) (always 10?)
181IF M>=N+S*K THEN 200If total mass >= capsule mass + mass of fuel burned in turn, continue at 200
190S=(M-N)/K(Else) (total mass < capsule + fuel burned) S: ratio of remaining fuel to burn rate
200GOSUB 420
201IF I<=O THEN 340
210IF V<=0 THEN 230
220IF J<0 THEN 370
230GOSUB 330
231GOTO 160
240PRINT "FUEL OUT AT";L;"SECONDS"240-261 Out-of-fuel/free-fall process
241S=(-V+SQR(V*V+2*A*G))/GS: time to free-fall to surface (s)
250V=V+G*SV: impact speed (mi/s)
251L=L+SL: mission time of impact (s)
260W=3600*VW: impact speed (mi/h)
261PRINT "ON MOON AT";L;"SECONDS - IMPACT VELOCITY";W;"MPH"
274IF W<=1.2 THEN PRINT "PERFECT LANDING!"
275GOTO 440
280IF W<=10 THEN PRINT "GOOD LANDING (COULD RE BETTER)"
281GOTO 440
282IF W>60 THEN 300
284PRINT "CRAFT DAMAGE... YOU'RE STRANDED HERE UNTIL A RESCUE"
286PRINT "PARTY ARRIVES. HOPE YOU HAVE ENOUGH OXYGEN!"
288GOTO 440
300PRINT "SORRY THERE NERE NO SURVIVORS. YOU BLOW IT!"
310PRINT "IN FACT, YOU BLASTED A NEW LUNAR CRATER";W*.227;"FEET DEEP!"
320GOTO 440
330L=L+S
331T=T-S
332M=M-S*K
333A=I
334V=J
335RETURN
340IF S<5E-03 THEN 260
350D=V+SQR(V*V+2*A*(G-Z*K/M))
351S=2*A/D
360GOSUB 420
361GOSUB 330
362GOTO 340
370W=(1-M*G/(Z*K))/2
371S=M*V/(Z*K*(W+SQR(W*W+V/Z)))+.05
372GOSUB 420
380IF I<=0 THEN 340
390GOSUB 330
391IF J>0 THEN 160
400IF V>0 THEN 370
410GOTO 160
420Q=S*K/M
421J=V+G*S+Z*(-Q-Q*Q/2-Q^3/3-Q^4/4-Q^5/5)
430I=A-G*S*S/2-V*S+Z*S*(Q/2+Q^2/6+Q^3/12+Q^4/20+Q^5/30)
431RETURN
440PRINT
441PRINT
442PRINT
443PRINT 'TRY AGAIN??"
444GOTO 70

Refactor

  1. Title/description/instructions (10-113) [add note on landing velocity]
  2. Display status header (131)
  3. Initialization: L (time (s))=0; A (alt. (mi))=120; V (speed (mi/s))=1; M (total mass (lbs))=33000 (120-145)
  4. Display status (150)
  5. Input fuel burn (151)