Merge branch 'main' into miniscript-batch-9 (resolved conflicts in favor of branch).

This commit is contained in:
JoeStrout
2023-10-06 07:46:29 -07:00
3 changed files with 304 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
Original source downloaded from [Vintage Basic](http://www.vintage-basic.net/games.html).
Conversion to [MiniScript](https://miniscript.org).
Ways to play:
1. Command-Line MiniScript:
Download for your system from https://miniscript.org/cmdline/, install, and then run the program with a command such as:
miniscript splat.ms
2. Mini Micro:
Download Mini Micro from https://miniscript.org/MiniMicro/, launch, and then click the top disk slot and chose "Mount Folder..." Select the folder containing the MiniScript program and this README file. Then, at the Mini Micro command prompt, enter:
load "splat"
run

View File

@@ -0,0 +1,133 @@
within5pct = function(n)
return n * (1 + rnd / 20 - rnd / 20)
end function
splatMsg = ["Requiescat in pace.", "May the Angel of Heaven lead you into Paradise.",
"Rest in piece.", "Son-Of-A-Gun.", "#$%&&%!$",
"A kick in the pants is a boost if you're headed right.",
"Hmm. Should have picked a shorter time.", "Mutter. Mutter. Mutter.",
"Pushing up daisies.", "Easy come, easy go."]
history = []
clear
print " " * 33 + "Splat"
print " " * 15 + "Creative Computing Morristown, New Jersey"
print;print;print
print "Welcome to 'Splat' -- the game that simulates a parachute"
print "jump. Try to open your chute at the last possible"
print "moment without going splat."
ans = "y"
while ans == "y"
print;print
distance = floor(9001 * rnd) + 1000
ans = input("Select your own terminal velocity (Yes or No)? ") + " "
if ans[0].lower == "y" then
terminalVel = input("What terminal velocity (mi/hr)? ").val
else
terminalVel = floor(1000 * rnd)
print "Ok. Terminal velocity = " + terminalVel + "mi/hr"
end if
terminalVel = terminalVel * 5280/3600
velocity = within5pct(terminalVel)
ans = input("Want to select acceleration due to gravity (Yes or No)? ") + " "
if ans[0].lower == "y" then
acceleration = input("What acceleration (ft/sec/sec)? ").val
acceleration = within5pct(acceleration)
else
bodies = ["Mercury", "Venus", "Earth", "the moon", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "the Sun"]
gravity = [12.2, 28.3,32.16,5.15,12.5,85.2,37.6,33.8,39.6,896]
initialStmt = ["Fine. You're on ", "All right. You're on ", "Then you're on "]
i = floor(rnd * 10)
acceleration = gravity[i]
stmt = initialStmt[i%3] + bodies[i] + ". Acceleration=" + acceleration + " ft/sec/sec."
print stmt
end if
actAccel = within5pct(acceleration)
print
print " Altitude = " + distance + " ft"
print " Term. Velocity = " + terminalVel + " ft/sec +/-5%"
print " Acceleration = " + acceleration + " ft/sec/sec +/-5%"
print "Set the timer for your freefall."
sec = input("How many seconds? ").val
print "Here we go."; print
print "Time (sec)" + char(9) + "Dist to Fall (ft)"
print "==========" + char(9) + "================="
termVelHit = false
for i in range(0, sec, sec/8)
sec = velocity/actAccel
if i <= sec and termVelHit == false then
dist = distance - ((actAccel/2)*i^2)
else if termVelHit == false then
termVelHit = true
print "Terminal velocity reached a T plus " + velocity/actAccel + " seconds."
end if
if termVelHit then
dist = distance - ((velocity^2/(2*actAccel))+(velocity*(i-sec)))
end if
if dist <= 0 then break
print (" " + i + " " * 9)[:9] + char(9) + " " + dist
end for
if dist > 0 then
print "Chute open"
history.push(dist)
numJumps = history.len
numLowerJumps = 0
for d in history
numLowerJumps += (dist <= d)
end for
jumpDiff = numJumps - numLowerJumps
if numJumps < 4 then
ordinal = ["1st", "2nd", "3rd"]
print "Amazing!! Not bad for your " + ordinal[numJumps-1] + " successful jump!!!"
else if jumpDiff <= numJumps * 0.10 then
print "Wow! That's some jumping. Of the " + numJumps + " successful jumps"
print "before yours, only " + jumpDiff + " opened their chutes lower than"
print "you did."
else if jumpDiff <= numJumps * 0.25 then
print "Pretty good! " + numJumps + " successful jumps preceded yours and only"
print jumpDiff + " of them got lower than you did before their chute"
print "opened."
else if jumpDiff <= numJumps * 0.50 then
print "Not bad. There have been " + numJumps + " successful jumps before yours."
print "You were beaten out by " + jumpDiff + " of them."
else if jumpDiff <= numJumps * 0.75 then
print "Conservative, aren't you? You ranked only " + jumpDiff + " in the"
print numJumps + " successful jumps before yours."
else if jumpDiff <= numJumps * 0.90 then
print "Humph! Don't you have any sporting blood? There were"
print numJumps + " successful jumps before yours and you came in " + numLowerJumps + " jumps"
print "better than the worst. Shape up!!!"
else
print "Hey! You pulled the rip code much too soon. " + numJumps + " successful"
print "jumps before yours and you came in number " + jumpDiff + "! Get with it."
end if
else if dist <= 0 and not termVelHit then
print (2 * distance / actAccel) ^ .5 + " " * 5 + "Splat"
else if dist <= 0 and termVelHit then
print velocity/actAccel + ((distance - (velocity^2/(2*actAccel)))/velocity) + " " *5 + "Splat"
end if
if dist <=0 then
splatMsg.shuffle
print splatMsg[0]
print "I'll give you another chance."
end if
ans = input("Do you want to play again? ") + " "
ans = ans[0].lower
end while
print "S" * 10
print

View File

@@ -0,0 +1,155 @@
solutions = [[0,1,2],[3,4,5],[6,7,8]]
solutions += [[0,3,6],[1,4,7],[2,5,8]]
solutions += [[0,4,8],[2,4,6]]
TicTacToe = {}
TicTacToe.grid = (" " * 9).split("")
TicTacToe.markers = {true: "X",false:"O"}
TicTacToe.AI = "X"
TicTacToe.human = "O"
TicTacToe.next = "X"
TicTacToe.lastMove = -1
TicTacToe.show = function
print " " + self.grid[0:3].join(" ! ")
print "---+---+---"
print " " + self.grid[3:6].join(" ! ")
print "---+---+---"
print " " + self.grid[6:].join(" ! ")
print
print
end function
TicTacToe.set = function(player, pos)
if self.grid[pos] != " " then
return false
end if
self.grid[pos] = player
self.lastMove = pos
return true
end function
TicTacToe.setMarkers = function(mark)
self.human = self.markers[mark == "X"]
self.AI = self.markers[mark == "O"]
end function
TicTacToe.getWinner = function
for mark in self.markers.values
for solution in solutions
cnt = 0
for i in solution
cnt += (self.grid[i] == mark)
end for
if cnt == 3 then return mark
end for
end for
return null
end function
TicTacToe.potentialWins = function
potential = {"X": [], "O": []}
for mark in self.markers.values
for solution in solutions
cnt = 0
emptyCells = []
for i in solution
cnt += (self.grid[i] == mark)
if self.grid[i] == " " then emptyCells.push(i)
end for
if cnt == 2 and emptyCells.len == 1 then potential[mark].push(emptyCells[0])
end for
end for
return potential
end function
TicTacToe.moveAvailable = function
return self.grid.indexOf(" ") != null
end function
TicTacToe.selectAI = function
if self.grid[4] == " " then return 4
potential = self.potentialWins
AIWins = potential[self.AI]
if AIWins.len >0 then return AIWins[0]
HumanWins = potential[self.human]
if HumanWins.len > 0 then return HumanWins[0]
if [1,3,5,7].indexOf(self.lastMove) != null then
for corner in [8,6,2,0]
if self.grid[corner] == " " then
self.grid[corner] = self.AI
potential = self.potentialWins
self.grid[corner] = " "
AIWins = potential[self.AI]
if AIWins.len > 0 then return corner
end if
end for
else
for side in [1,3,5,7]
if self.grid[side] == " " then
self.grid[side] = self.AI
potential = self.potentialWins
self.grid[side] = " "
AIWins = potential[self.AI]
if AIWins.len > 0 then return side
end if
end for
end if
for ix in range(0,8)
if self.grid[ix] == " " then return ix
end for
return null
end function
print " " * 15 + "Creative Computing Morristown, New Jersey"
print; print; print
print "The board is numbered."
print; print; print
print " 1 2 3"
print " 4 5 6"
print " 7 8 9"
print
ans = input("Do you want to 'X' or 'O'? ")
if ans.upper != "X" then ans = "O"
TicTacToe.setMarkers(ans.upper)
winner = null
print
while TicTacToe.moveAvailable and winner == null
if TicTacToe.next == TicTacToe.AI then
move = TicTacToe.selectAI
TicTacToe.set(TicTacToe.AI, move)
TicTacToe.next = TicTacToe.human
print "The computer moves to..."
else
move = input("Where do you move? ").val
if move < 1 or move > 9 then
print "Thanks for the game."
exit
else if not TicTacToe.set(TicTacToe.human, move-1) then
print "That square is occupied."
print
continue
else
TicTacToe.next = TicTacToe.AI
end if
end if
TicTacToe.show
winner = TicTacToe.getWinner
end while
if winner == null then
print "It's a draw. Thank you."
else if winner == TicTacToe.AI then
print "I win, turkey!!"
else
print "You beat me! Good game!"
end if