Skip to content

Commit bc8156f

Browse files
committed
Added MiniScript implementation of lunar.bas.
1 parent ae81f67 commit bc8156f

File tree

1 file changed

+114
-0
lines changed
  • 00_Alternate_Languages/59_Lunar_LEM_Rocket/MiniScript

1 file changed

+114
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
print " "*33 + "Lunar"
2+
print " "*15 + "Creative Computing Morristown, New Jersey"
3+
print; print; print
4+
print "This is a computer simulation of an Apollo lunar"
5+
print "landing capsule."; print; print
6+
print "The on-board computer has failed (it was made by"
7+
print "Xerox) so you have to land the capsule manually."
8+
9+
printCols = function(fields, delimiter=null)
10+
if delimiter == null then delimiter = text.delimiter
11+
line = ""
12+
for s in fields
13+
line += (s + " "*12)[:12]
14+
end for
15+
print line, delimiter
16+
end function
17+
18+
doOneGame = function
19+
print; print "Set burn rate of retro rockets to any value between"
20+
print "0 (free fall) and 200 (maximum burn) pounds per second."
21+
print "Set new burn rate every 10 seconds."; print
22+
print "Capsule weight 32,500 lbs; fuel weight 16,500 lbs."
23+
print; print; print; print "Good luck"
24+
l = 0
25+
26+
print
27+
printCols ["sec","mi + ft","mph","lb fuel","burn rate"]
28+
print
29+
a=120; v = 1; m=33000; n=16500; g=1e-03; z = 1.8
30+
31+
formulaSet1 = function // (subroutine 330)
32+
outer.l += s
33+
outer.t -= s
34+
outer.m -= s * k
35+
outer.a = i
36+
outer.v = j
37+
end function
38+
39+
formulaSet2 = function // (subroutine 420)
40+
outer.q = s * k / m
41+
outer.j = v + g*s + z*(-q-q*q/2-q^3/3-q^4/4-q^5/5)
42+
outer.i = a - g*s*s/2 - v*s+z*s*(q/2+q^2/6+q^3/12+q^4/20+q^5/30)
43+
end function
44+
45+
formulaSet3 = function // (loop 340-360)
46+
while s >= 5e-3
47+
outer.d = v + sqrt(v * v + 2 * a * (g - z * k / m))
48+
outer.s = 2 * a / d
49+
formulaSet2
50+
formulaSet1
51+
end while
52+
end function
53+
54+
while true
55+
printCols [l, floor(a) + " " + floor(5280*(a-floor(a))), 3600*v, m-n], ""
56+
k = input.val
57+
t=10
58+
shouldExit = false
59+
60+
while true
61+
if m-n < 1e-03 then break
62+
if t < 1e-03 then break
63+
s = t; if m < n+s*k then s = (m-n)/k
64+
formulaSet2
65+
if i <= 0 then
66+
formulaSet3
67+
shouldExit = true
68+
break
69+
end if
70+
if v > 0 and j < 0 then
71+
while v > 0 and j <= 0
72+
w = (1 - m*g/(z*k))/2
73+
s = m*v / (z*k*(w + sqrt(w*w + v/z))) + 0.05
74+
formulaSet2
75+
if i <= 0 then
76+
formulaSet3
77+
shouldExit = true
78+
break
79+
end if
80+
formulaSet1
81+
end while
82+
if shouldExit then break
83+
continue
84+
end if
85+
formulaSet1
86+
end while
87+
if shouldExit then break
88+
if m-n < 1e-03 then
89+
print "Fuel out at " + round(l) + " seconds"
90+
s = (-v+sqrt(v*v+2*a*g))/g
91+
v = v+g*s; l = l+s
92+
break
93+
end if
94+
end while
95+
96+
w = 3600*v
97+
print "On moon at " + l + " seconds - impact velocity " + round(w,1) + " mph"
98+
if w <= 1.2 then
99+
print "Perfect landing!"
100+
else if w <= 10 then
101+
print "Good landing (could be better)"
102+
else if w <= 60 then
103+
print "Craft damage... you're stranded here until a rescue"
104+
print "party arrives. Hope you have enough oxygen!"
105+
else
106+
print "Sorry there were no survivors. You blew it!"
107+
print "In fact, you blasted a new lunar crater " + round(w*.227,1) + " feet deep!"
108+
end if
109+
end function
110+
111+
while true
112+
doOneGame
113+
print; print; print; print "Try again??"
114+
end while

0 commit comments

Comments
 (0)