mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-21 23:00:43 -08:00
Added MiniScript port of 33_Dice
This commit is contained in:
3
00_Alternate_Languages/33_Dice/MiniScript/README.md
Normal file
3
00_Alternate_Languages/33_Dice/MiniScript/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Original source downloaded from [Vintage Basic](http://www.vintage-basic.net/games.html).
|
||||||
|
|
||||||
|
Conversion to [MiniScript](https://miniscript.org).
|
||||||
53
00_Alternate_Languages/33_Dice/MiniScript/dice.ms
Normal file
53
00_Alternate_Languages/33_Dice/MiniScript/dice.ms
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
// Dice
|
||||||
|
//
|
||||||
|
// Danny Freidus
|
||||||
|
// Ported from BASIC to MiniScript by Joe Strout
|
||||||
|
|
||||||
|
print " "*34 + "DICE"
|
||||||
|
print " "*15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
||||||
|
print; print; print
|
||||||
|
print "This program simulates the rolling of a"
|
||||||
|
print "pair of dice."
|
||||||
|
print "You enter the number of times you want the computer to"
|
||||||
|
print "'roll' the dice. Watch out, very large numbers take"
|
||||||
|
print "a long time. In particular, numbers over 5000."
|
||||||
|
|
||||||
|
// Function to do one run of the simulation.
|
||||||
|
runOnce = function
|
||||||
|
// Clear the array we'll use to hold the counts
|
||||||
|
counts = [0] * 13
|
||||||
|
// Loop the desired number of times
|
||||||
|
x = input("How many rolls? ").val
|
||||||
|
for s in range(1, x)
|
||||||
|
// roll two dice and find the sum
|
||||||
|
die1 = ceil(6 * rnd)
|
||||||
|
die2 = ceil(6 * rnd)
|
||||||
|
sum = die1 + die2
|
||||||
|
// update the count for that sum
|
||||||
|
counts[sum] += 1
|
||||||
|
end for
|
||||||
|
print
|
||||||
|
|
||||||
|
// print a table showing how many times each sum was rolled
|
||||||
|
print "Total Spots Number of Times"
|
||||||
|
for v in range(2, 12)
|
||||||
|
// (the [-6:] trick below right-aligns the number)
|
||||||
|
print (" " + v)[-6:] + " "*10 + counts[v]
|
||||||
|
end for
|
||||||
|
print; print
|
||||||
|
end function
|
||||||
|
|
||||||
|
// Get a yes/no (or at least y/n) response from the user.
|
||||||
|
askYesNo = function(prompt)
|
||||||
|
while true
|
||||||
|
answer = input(prompt).lower[:1]
|
||||||
|
if answer == "y" or answer == "n" then return answer
|
||||||
|
end while
|
||||||
|
end function
|
||||||
|
|
||||||
|
// main loop
|
||||||
|
while true
|
||||||
|
print
|
||||||
|
runOnce
|
||||||
|
if askYesNo("Try again? ") == "n" then break
|
||||||
|
end while
|
||||||
Reference in New Issue
Block a user