mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-02-04 11:07:59 -08:00
Merge pull request #912 from JoeStrout/miniscript-tweaks
Miniscript tweaks
This commit is contained in:
@@ -63,7 +63,7 @@ doOneGame = function
|
||||
for i in range(1,12); ps[i][1] = "X"; end for
|
||||
for i in range(1, 7); ps[1][i] = "X"; end for; ps[2][7] = "X"
|
||||
secretWord = words.pull.upper
|
||||
print "(Secret word: " + secretWord + ")"
|
||||
//print "(Secret word: " + secretWord + ")"
|
||||
visibleWord = ["-"] * secretWord.len
|
||||
wrongGuesses = 0
|
||||
while true
|
||||
|
||||
@@ -78,7 +78,7 @@ while true
|
||||
while true
|
||||
inp = input(" Driver to " + name + ": Where does " + buyer + " live? ")
|
||||
inp = inp.replace(",", " ").replace(" ", " ")
|
||||
inp = inp.split + [0,0]
|
||||
inp = inp.split + ["0","0"]
|
||||
guess = [inp[0].val, inp[1].val]
|
||||
if 1 <= guess[0] <= 4 and 1 <= guess[1] <= 4 then break
|
||||
end while
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
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 slots.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 "slots"
|
||||
run
|
||||
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 slots.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 "slots"
|
||||
run
|
||||
```
|
||||
|
||||
@@ -1,125 +1,108 @@
|
||||
center = function(s,n)
|
||||
h = floor((n - s.len)/2)
|
||||
s = " " * h + s + " " * n
|
||||
return s[:n]
|
||||
end function
|
||||
print " "*30 + "Slots"
|
||||
print " "*15 + "Creative Computing Morristown New Jersey"
|
||||
print; print; print
|
||||
|
||||
Machine = {"symbols": ["Bar", "Bell", "Orange", "Lemon", "Plum ", "Cherry"]}
|
||||
Machine.money = 0
|
||||
Machine.bet = 0
|
||||
Machine.playing = true
|
||||
Machine.reels = [0,0,0]
|
||||
Machine.results = null
|
||||
// PRODUCED BY FRED MIRABELLE AND BOB HARPER ON JAN 29, 1973
|
||||
// IT SIMULATES THE SLOT MACHINE.
|
||||
// (Ported to MiniScript by Joe Strout on Oct 04, 2023)
|
||||
|
||||
Machine.reelsSpin = function(n, msg, row)
|
||||
env = [1,.95,.9,.85,.25,.2,.15,.1,.05,0]
|
||||
bell = new Sound
|
||||
bell.init .1, 800, env, Sound.sineWave
|
||||
for i in range(1,2)
|
||||
s1 = new Sound
|
||||
s1.init .2, i * 800 + 800, env, Sound.sineWave
|
||||
bell.mix(s1, 1 / (2 ^ i))
|
||||
end for
|
||||
for i in range(1,n)
|
||||
bell.play
|
||||
ix = 0
|
||||
while bell.isPlaying
|
||||
text.row = row
|
||||
ix = (ix + 1) % self.symbols.len
|
||||
print msg + center(self.symbols[ix],8)
|
||||
end while
|
||||
end for
|
||||
end function
|
||||
|
||||
Machine.makeBet = function()
|
||||
while true
|
||||
bet = floor(input("Your bet? ").val)
|
||||
if bet > 100 then
|
||||
print "House limits are $100"
|
||||
else if bet < 1 then
|
||||
print "Minimum bet is $1"
|
||||
else
|
||||
break
|
||||
end if
|
||||
end while
|
||||
Machine.bet = bet
|
||||
end function
|
||||
|
||||
Machine.pullHandle = function
|
||||
if text.row < 3 then
|
||||
print; print
|
||||
text.row = text.row + 2
|
||||
end if
|
||||
row = text.row
|
||||
msg = ""
|
||||
for i in range(0,2)
|
||||
self.reelsSpin(5 + 5 * (i==0), msg, row)
|
||||
wait .1
|
||||
symIx = floor(rnd * self.symbols.len)
|
||||
msg += center(self.symbols[symIx],9)
|
||||
self.reels[i] = symIx
|
||||
text.row = row
|
||||
print msg
|
||||
end for
|
||||
end function
|
||||
|
||||
Machine.winnings = function
|
||||
bet = Machine.bet
|
||||
barIdx = self.symbols.indexOf("Bar")
|
||||
numBars = 0
|
||||
multiples = 0
|
||||
for i in range(0,2)
|
||||
numBars += (self.reels[i] == barIdx)
|
||||
multiples += (self.reels[i] == self.reels[(i + 1) % 3])
|
||||
end for
|
||||
|
||||
if numBars == 3 then return {"won": bet * 101, "msg": "***Jackpot***"}
|
||||
if numBars == 2 then return {"won": bet * 6, "msg": "*Double Bar*"}
|
||||
if multiples == 3 then return {"won": bet * 11, "msg": "**Top Dollar**"}
|
||||
if multiples == 1 then return {"won": bet * 3, "msg": "Double!!"}
|
||||
return {"won": -bet, "msg": "You lost."}
|
||||
end function
|
||||
|
||||
Machine.results = function
|
||||
result = Machine.winnings
|
||||
self.money += result.won
|
||||
print result.msg
|
||||
if result.won > 0 then
|
||||
print "You Won!!"
|
||||
end if
|
||||
print "Your standings are $" + self.money
|
||||
return
|
||||
end function
|
||||
|
||||
Machine.playAgain = function
|
||||
ans = input("Again? ") + " "
|
||||
self.playing = (ans[0].lower == "y")
|
||||
if self.playing then return
|
||||
print
|
||||
if self.money < 0 then
|
||||
print "Pay up! Please leave your money on the terminal."
|
||||
else if self.money == 0 then
|
||||
print "Hey, you broke even."
|
||||
else
|
||||
print "Collect your winnings from the H&M cashier."
|
||||
end if
|
||||
end function
|
||||
|
||||
clear
|
||||
print " " * 30 + "Slots"
|
||||
print " " * 15 + "Creative Computing Morristown, New Jersey"
|
||||
print;print;print
|
||||
print "You are in the H&M Casino, in front of one of our"
|
||||
print "You are in the H&M casino,in front of one of our"
|
||||
print "one-arm bandits. Bet from $1 to $100."
|
||||
print "to pull the arm, punch the return key after making your bet."
|
||||
print "To pull the arm, punch the return key after making your bet."
|
||||
|
||||
print
|
||||
while Machine.playing
|
||||
Machine.makeBet
|
||||
symbols = ["BAR", "BELL", "ORANGE", "LEMON", "PLUM", "CHERRY"]
|
||||
|
||||
|
||||
winTriple = function(symbol, bet)
|
||||
if symbol == "BAR" then
|
||||
print "***JACKPOT***"
|
||||
globals.profit += 101 * bet
|
||||
else
|
||||
print "**TOP DOLLAR**"
|
||||
globals.profit += 11 * bet
|
||||
end if
|
||||
print "You won!"
|
||||
end function
|
||||
|
||||
winDouble = function(symbol, bet)
|
||||
if symbol == "BAR" then
|
||||
print "*DOUBLE BAR*"
|
||||
globals.profit += 6 * bet
|
||||
else
|
||||
print "Double!"
|
||||
globals.profit += 3 * bet
|
||||
end if
|
||||
print "You won!"
|
||||
end function
|
||||
|
||||
lose = function(bet)
|
||||
print "You lost."
|
||||
globals.profit -= bet
|
||||
end function
|
||||
|
||||
calcWinLoss = function(spun, bet)
|
||||
if spun[0] == spun[1] then
|
||||
if spun[0] == spun[2] then
|
||||
winTriple spun[0], bet
|
||||
else
|
||||
winDouble spun[0], bet
|
||||
end if
|
||||
else if spun[0] == spun[2] then
|
||||
winDouble spun[0], bet
|
||||
else if spun[1] == spun[2] then
|
||||
winDouble spun[1], bet
|
||||
else
|
||||
lose bet
|
||||
end if
|
||||
end function
|
||||
|
||||
ringBells = function(qty=5)
|
||||
// I believe all the obnoxious beeping was to slow down the game
|
||||
// and build suspense as each "wheel" appears. Our version:
|
||||
wait 0.1
|
||||
for i in range(1, qty)
|
||||
print char(7), ""
|
||||
wait 0.05
|
||||
end for
|
||||
end function
|
||||
|
||||
// Main program
|
||||
profit = 0
|
||||
while true
|
||||
print
|
||||
Machine.pullHandle
|
||||
|
||||
// Get bet
|
||||
while true
|
||||
bet = input("Your bet? ").val
|
||||
if 1 <= bet <= 100 then break
|
||||
if bet < 1 then print "Minimum bet is $1" else print "House limits are $100"
|
||||
end while
|
||||
|
||||
// Spin 3 wheels (randomly picking a symbol for each one)
|
||||
spun = []
|
||||
spun.push symbols[rnd * symbols.len]
|
||||
spun.push symbols[rnd * symbols.len]
|
||||
spun.push symbols[rnd * symbols.len]
|
||||
print
|
||||
Machine.results
|
||||
Machine.playAgain
|
||||
ringBells 10; print spun[0], " "
|
||||
ringBells 5; print spun[1], " "
|
||||
ringBells 5; print spun[2]
|
||||
print
|
||||
|
||||
// Calculate and display win/loss
|
||||
wait 0.5
|
||||
calcWinLoss spun, bet
|
||||
|
||||
// Show new state, and maybe play again
|
||||
print "Your standings are $ " + profit
|
||||
yn = input("Again? ").lower + " "
|
||||
if yn[0] != "y" then break
|
||||
end while
|
||||
|
||||
if profit == 0 then
|
||||
print "Hey, you broke even."
|
||||
else if profit > 0 then
|
||||
print "Collect your winnings from the H&M cashier."
|
||||
else
|
||||
print "Pay up! Please leave your money on the terminal."
|
||||
end if
|
||||
|
||||
@@ -6,11 +6,13 @@ 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
|
||||
```
|
||||
|
||||
@@ -9,7 +9,7 @@ splatMsg = ["Requiescat in pace.", "May the Angel of Heaven lead you into Paradi
|
||||
"Pushing up daisies.", "Easy come, easy go."]
|
||||
|
||||
history = []
|
||||
clear
|
||||
//clear // (works on Mini Micro only)
|
||||
print " " * 33 + "Splat"
|
||||
print " " * 15 + "Creative Computing Morristown, New Jersey"
|
||||
print;print;print
|
||||
|
||||
@@ -6,11 +6,13 @@ 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 stars.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 "stars"
|
||||
run
|
||||
run
|
||||
```
|
||||
|
||||
18
00_Alternate_Languages/83_Stock_Market/MiniScript/README.md
Normal file
18
00_Alternate_Languages/83_Stock_Market/MiniScript/README.md
Normal file
@@ -0,0 +1,18 @@
|
||||
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 stockmarket.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 "stockmarket"
|
||||
run
|
||||
```
|
||||
199
00_Alternate_Languages/83_Stock_Market/MiniScript/stockmarket.ms
Normal file
199
00_Alternate_Languages/83_Stock_Market/MiniScript/stockmarket.ms
Normal file
@@ -0,0 +1,199 @@
|
||||
print " "*30 + "Stock Market"
|
||||
print " "*15 + "Creative Computing Morristown New Jersey"
|
||||
print; print; print
|
||||
|
||||
// Stock Market Simulation -STOCK-
|
||||
// Revised 8/18/70 (D. Pessel, L. Braun, C. Losik)
|
||||
// Ported to MiniScript 10/07/23 (J. Strout)
|
||||
|
||||
|
||||
// Ask a yes/no question; return true if yes, false if no
|
||||
yes = function(prompt)
|
||||
while true
|
||||
response = input(prompt + " (YES-Type 1, NO-Type 0)? ")
|
||||
if not response then continue
|
||||
if response == "1" or response[0].lower == "y" then return true
|
||||
if response == "0" or response[0].lower == "n" then return false
|
||||
end while
|
||||
end function
|
||||
|
||||
printInstructions = function
|
||||
print; print
|
||||
print "This program plays the stock market. You will be given"
|
||||
print "$10,000 and may buy or sell stocks. The stock prices will"
|
||||
print "be generated randomly and therefore this model does not"
|
||||
print "represent exactly what happens on the exchange. A table"
|
||||
print "of available stocks, their prices, and the number of shares"
|
||||
print "in your portfolio will be printed. Following this, the"
|
||||
print "initials of each stock will be printed with a question"
|
||||
print "mark. Here you indicate a transaction. To buy a stock"
|
||||
print "type +NNN, to sell a stock type -NNN, where NNN is the"
|
||||
print "number of shares. A brokerage fee of 1% will be charged"
|
||||
print "on all transactions. Note that if a stock's value drops"
|
||||
print "to zero it may rebound to a positive value again. You"
|
||||
print "have $10,000 to invest. Use integers for all your inputs."
|
||||
print "(Note: To get a 'feel' for the market run for at least"
|
||||
print "10 days)"
|
||||
print "-----Good luck!-----"
|
||||
print
|
||||
input "(Press Return to continue.)"
|
||||
end function
|
||||
|
||||
randomIndex = function; return floor(rnd * stockPrices.len); end function
|
||||
|
||||
// Randomly produce new stock values based on previous day's values.
|
||||
// N1,N2 are random numbers of days which respectively determine
|
||||
// when a stock will increase or decrease 10 points.
|
||||
adjustStockPrices = function
|
||||
for i in changePerShare.indexes
|
||||
changePerShare[i] = 0
|
||||
end for
|
||||
// if N1 days have passed, increase a random stock by 10
|
||||
if N1 < 1 then
|
||||
changePerShare[randomIndex] = 10
|
||||
globals.N1 = floor(4.99 * rnd + 1)
|
||||
end if
|
||||
// if N2 days have passed, decrease a random stock by 10
|
||||
if N2 < 1 then
|
||||
changePerShare[randomIndex] = -10
|
||||
globals.N2 = floor(4.99 * rnd + 1)
|
||||
end if
|
||||
// Deduct one day from N1 and N2
|
||||
globals.N1 -= 1
|
||||
globals.N2 -= 1
|
||||
// update all stocks
|
||||
for i in stockPrices.indexes
|
||||
smallChange = rnd
|
||||
if smallChange < 0.25 then smallChange = 0.25
|
||||
if smallChange > 0.5 then smallChange = 0.5
|
||||
changePerShare[i] += marketTrendSlope * stockPrices[i] + smallChange + floor(3 - 6*rnd + 0.5)
|
||||
changePerShare[i] = round(changePerShare[i], 2)
|
||||
stockPrices[i] += changePerShare[i]
|
||||
if stockPrices[i] < 0 then
|
||||
changePerShare[i] = 0
|
||||
stockPrices[i] = 0
|
||||
end if
|
||||
stockPrices[i] = round(stockPrices[i], 2)
|
||||
end for
|
||||
// After trendDaysLeft, randomly change trend sign and slope
|
||||
globals.trendDaysLeft -= 1
|
||||
if trendDaysLeft < 1 then
|
||||
globals.trendDaysLeft = floor(4.99 * rnd + 1)
|
||||
globals.marketTrendSlope = floor(rnd*10 + 0.5)/100
|
||||
if rnd < 0.5 then globals.marketTrendSlope = -marketTrendSlope
|
||||
end if
|
||||
end function
|
||||
|
||||
pad = function(s, width=20)
|
||||
s = str(s)
|
||||
return s + " "*(width - s.len)
|
||||
end function
|
||||
|
||||
printInitialPortfolio = function
|
||||
print pad("Stock", 30) + pad("Initials", 12) + "Price/Share"
|
||||
for i in stockSymbols.indexes
|
||||
print pad(stockNames[i], 32) + pad(stockSymbols[i], 14) + stockPrices[i]
|
||||
end for
|
||||
end function
|
||||
|
||||
printMarketResults = function
|
||||
print
|
||||
print "********** END OF DAY'S TRADING **********"
|
||||
print
|
||||
print
|
||||
print pad("Stock", 8) + pad("Price/Share", 14) + pad("Holdings", 12) +
|
||||
pad("Value", 10) + "Net Price Change"
|
||||
for i in stockSymbols.indexes
|
||||
value = round(stockPrices[i] + sharesOwned[i], 2)
|
||||
print pad(stockSymbols[i], 9) + pad(stockPrices[i], 14) +
|
||||
pad(sharesOwned[i], 12) + pad(value, 10) + changePerShare[i]
|
||||
end for
|
||||
print
|
||||
end function
|
||||
|
||||
printStatus = function
|
||||
average = stockPrices.sum / stockPrices.len
|
||||
print
|
||||
print "New York Stock Exchange Average: " + round(average, 2), ""
|
||||
if prevAverage != null then
|
||||
print " Net Change " + round(average - prevAverage, 2)
|
||||
else
|
||||
print
|
||||
end if
|
||||
globals.prevAverage = average
|
||||
print
|
||||
stockValue = 0
|
||||
for i in stockPrices.indexes
|
||||
stockValue += stockPrices[i] * sharesOwned[i]
|
||||
end for
|
||||
print "Total stock assets are $ " + round(stockValue, 2)
|
||||
print "Total cash assets are $ " + round(cash, 2)
|
||||
print "Total assets are $ " + round(stockValue + cash, 2)
|
||||
print
|
||||
// Uncomment the following line to cheat/debug:
|
||||
//print "marketTrendSlope: " + marketTrendSlope + "; trendDaysLeft: " + trendDaysLeft
|
||||
end function
|
||||
|
||||
// Calculate total cost, including brokerage fee, to buy the given
|
||||
// stock (or if qtyToBuy < 0, negative cash gains minus the fee).
|
||||
totalCost = function(stockIndex, qtyToBuy)
|
||||
baseVal = stockPrices[stockIndex] * qtyToBuy
|
||||
fee = round(abs(baseVal) * 0.01, 2)
|
||||
return baseVal + fee
|
||||
end function
|
||||
|
||||
buySell = function
|
||||
print "What is your transaction in"
|
||||
i = 0
|
||||
while i < stockSymbols.len
|
||||
while true
|
||||
qty = input(stockSymbols[i] + "? ")
|
||||
if qty == "" or qty == "0" or qty.val != 0 then break
|
||||
print "Enter quantity to buy/sell like +10 or -2."
|
||||
end while
|
||||
qty = qty.val
|
||||
if qty < 0 and -qty > sharesOwned[i] then
|
||||
print "You have only " + sharesOwned[i] + " of " + stockSymbols[i] + "; try again."
|
||||
continue
|
||||
end if
|
||||
if totalCost(i, qty) > cash then
|
||||
print "This would cost " + (totalCost(i, qty) - cash) + " more than you have."
|
||||
continue
|
||||
end if
|
||||
sharesOwned[i] += qty
|
||||
globals.cash -= totalCost(i, qty)
|
||||
i += 1
|
||||
end while
|
||||
end function
|
||||
|
||||
// Introduction
|
||||
if yes("Do you want the instructions") then printInstructions
|
||||
print; print
|
||||
|
||||
// Initial stock values and trends
|
||||
stockSymbols = ["IBM", "RCA", "LBJ", "ABC", "CBS"]
|
||||
stockNames = ["Int. Ballistic Missiles", "Red Cross of America",
|
||||
"Lichtenstein, Bumrap & Joke", "American Bankrupt Co.", "Censured Books Store"]
|
||||
sharesOwned = [0] * stockSymbols.len
|
||||
cash = 10000
|
||||
stockPrices = [100, 85, 150, 140, 110]
|
||||
changePerShare = [0] * stockSymbols.len
|
||||
trendDaysLeft = floor(4.99 * rnd + 1)
|
||||
marketTrendSlope = floor(rnd*10 + 0.5)/100
|
||||
if rnd > 0.5 then marketTrendSlope = -marketTrendSlope
|
||||
N1 = 0 // days until a big positive jump in a random price
|
||||
N2 = 0 // days until a big negative jump in a random price
|
||||
adjustStockPrices
|
||||
prevAverage = null
|
||||
|
||||
printInitialPortfolio
|
||||
printStatus
|
||||
while true
|
||||
buySell
|
||||
adjustStockPrices
|
||||
printMarketResults
|
||||
printStatus
|
||||
if not yes("Do you wish to continue") then break
|
||||
end while
|
||||
print "Hope you had fun!!"
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
Original source downloaded from [Vintage Basic](http://www.vintage-basic.net/games.html).
|
||||
|
||||
Conversion to [MiniScript](https://miniscript.org). Note that while the original game separated the instructions into a separate BASIC program (probably due to memory limitations), we have chosen here to combine them into one MiniScript program with both instructions and gameplay. The instructions are available at the start of the game, and later at any time via the HLP command.
|
||||
|
||||
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 superstartrek.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 "superstartrek"
|
||||
run
|
||||
```
|
||||
File diff suppressed because it is too large
Load Diff
@@ -57,7 +57,7 @@ OF THE STARSHIP ENTERPRISE:
|
||||
ITSELF IS EQUIVALENT TO 1.0"
|
||||
COURSE
|
||||
ONE WARP FACTOR IS THE SIZE OF
|
||||
ONE QUADTANT. THEREFORE, TO GET
|
||||
ONE QUADRANT. THEREFORE, TO GET
|
||||
FROM QUADRANT 6,5 TO 5,5, YOU WOULD
|
||||
USE COURSE 3, WARP FACTOR 1.
|
||||
|
||||
@@ -77,7 +77,7 @@ OF THE STARSHIP ENTERPRISE:
|
||||
OF THE ENTERPRISE (WHICH IS IN THE MIDDLE OF THE SCAN)
|
||||
THE SCAN IS CODED IN THE FORM \###\, WHERE TH UNITS DIGIT
|
||||
IS THE NUMBER OF STARS, THE TENS DIGIT IS THE NUMBER OF
|
||||
STARBASES, AND THE HUNDRESDS DIGIT IS THE NUMBER OF
|
||||
STARBASES, AND THE HUNDREDS DIGIT IS THE NUMBER OF
|
||||
KLINGONS.
|
||||
|
||||
EXAMPLE - 207 = 2 KLINGONS, NO STARBASES, & 7 STARS.
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
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 qubit.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 "qubit"
|
||||
run
|
||||
```
|
||||
361
00_Alternate_Languages/88_3-D_Tic-Tac-Toe/MiniScript/qubit.ms
Normal file
361
00_Alternate_Languages/88_3-D_Tic-Tac-Toe/MiniScript/qubit.ms
Normal file
@@ -0,0 +1,361 @@
|
||||
print " "*33 + "QUBIC"
|
||||
print " "*15 + "Creative Computing Morristown New Jersey"
|
||||
print; print; print
|
||||
|
||||
getYesNo = function(prompt)
|
||||
while true
|
||||
yn = input(prompt + "? ").lower + " "
|
||||
if yn[0] == "y" then return "yes"
|
||||
if yn[0] == "n" then return "no"
|
||||
print "Incorrect answer. Please type 'yes' or 'no'"
|
||||
end while
|
||||
end function
|
||||
|
||||
// Data defining "lines" as sets of board indexes which form 4-in-a-row:
|
||||
ma = [null,
|
||||
[null, 1,2,3,4], // 1
|
||||
[null, 5,6,7,8], // 2
|
||||
[null, 9,10,11,12], // 3
|
||||
[null, 13,14,15,16], // 4
|
||||
[null, 17,18,19,20], // 5
|
||||
[null, 21,22,23,24], // 6
|
||||
[null, 25,26,27,28], // 7
|
||||
[null, 29,30,31,32], // 8
|
||||
[null, 33,34,35,36], // 9
|
||||
[null, 37,38,39,40], // 10
|
||||
[null, 41,42,43,44], // 11
|
||||
[null, 45,46,47,48], // 12
|
||||
[null, 49,50,51,52], // 13
|
||||
[null, 53,54,55,56], // 14
|
||||
[null, 57,58,59,60], // 15
|
||||
[null, 61,62,63,64], // 16
|
||||
[null, 1,17,33,49], // 17
|
||||
[null, 5,21,37,53], // 18
|
||||
[null, 9,25,41,57], // 19
|
||||
[null, 13,29,45,61], // 20
|
||||
[null, 2,18,34,50], // 21
|
||||
[null, 6,22,38,54], // 22
|
||||
[null, 10,26,42,58], // 23
|
||||
[null, 14,30,46,62], // 24
|
||||
[null, 3,19,35,51], // 25
|
||||
[null, 7,23,39,55], // 26
|
||||
[null, 11,27,43,59], // 27
|
||||
[null, 15,31,47,63], // 28
|
||||
[null, 4,20,36,52], // 29
|
||||
[null, 8,24,40,56], // 30
|
||||
[null, 12,28,44,60], // 31
|
||||
[null, 16,32,48,64], // 32
|
||||
[null, 1,5,9,13], // 33
|
||||
[null, 17,21,25,29], // 34
|
||||
[null, 33,37,41,45], // 35
|
||||
[null, 49,53,57,61], // 36
|
||||
[null, 2,6,10,14], // 37
|
||||
[null, 18,22,26,30], // 38
|
||||
[null, 34,38,42,46], // 39
|
||||
[null, 50,54,58,62], // 40
|
||||
[null, 3,7,11,15], // 41
|
||||
[null, 19,23,27,31], // 42
|
||||
[null, 35,39,43,47], // 43
|
||||
[null, 51,55,59,63], // 44
|
||||
[null, 4,8,12,16], // 45
|
||||
[null, 20,24,28,32], // 46
|
||||
[null, 36,40,44,48], // 47
|
||||
[null, 52,56,60,64], // 48
|
||||
[null, 1,6,11,16], // 49
|
||||
[null, 17,22,27,32], // 50
|
||||
[null, 33,38,43,48], // 51
|
||||
[null, 49,54,59,64], // 52
|
||||
[null, 13,10,7,4], // 53
|
||||
[null, 29,26,23,20], // 54
|
||||
[null, 45,42,39,36], // 55
|
||||
[null, 61,58,55,52], // 56
|
||||
[null, 1,21,41,61], // 57
|
||||
[null, 2,22,42,62], // 58
|
||||
[null, 3,23,43,63], // 59
|
||||
[null, 4,24,44,64], // 60
|
||||
[null, 49,37,25,13], // 61
|
||||
[null, 50,38,26,14], // 62
|
||||
[null, 51,39,27,15], // 63
|
||||
[null, 52,40,28,16], // 64
|
||||
[null, 1,18,35,52], // 65
|
||||
[null, 5,22,39,56], // 66
|
||||
[null, 9,26,43,60], // 67
|
||||
[null, 13,30,47,64], // 68
|
||||
[null, 49,34,19,4], // 69
|
||||
[null, 53,38,23,8], // 70
|
||||
[null, 57,42,27,12], // 71
|
||||
[null, 61,46,31,16], // 72
|
||||
[null, 1,22,43,64], // 73
|
||||
[null, 16,27,38,49], // 74
|
||||
[null, 4,23,42,61], // 75
|
||||
[null, 13,26,39,52]] // 76
|
||||
|
||||
// "opening book", i.e. spots that are generally good to hold if available
|
||||
ya = [null, 1,49,52,4,13,61,64,16,22,39,23,38,26,42,27,43]
|
||||
|
||||
showBoard = function
|
||||
for i in range(1,9); print; end for
|
||||
for i in range(1, 4)
|
||||
print
|
||||
for j in range(1, 4)
|
||||
str = " " * j
|
||||
for k in range(1, 4)
|
||||
q = 16 * i + 4 * j + k - 20
|
||||
if xa[q] == 5 then
|
||||
str += "(M)"
|
||||
else if xa[q] == 1 then
|
||||
str += "(Y)"
|
||||
else
|
||||
str += "( )"
|
||||
end if
|
||||
str += " "
|
||||
end for
|
||||
print str
|
||||
// print (makes display too tall for the screen)
|
||||
end for
|
||||
print
|
||||
end for
|
||||
end function
|
||||
|
||||
clearFractions = function
|
||||
for i in range(1, 64)
|
||||
if xa[i] == 1/8 then xa[i] = 0
|
||||
end for
|
||||
end function
|
||||
|
||||
checkForLines = function
|
||||
for s in range(1, 76)
|
||||
j1 = ma[s][1];
|
||||
j2 = ma[s][2];
|
||||
j3 = ma[s][3];
|
||||
j4 = ma[s][4];
|
||||
la[s] = xa[j1] + xa[j2] + xa[j3] + xa[j4]
|
||||
end for
|
||||
end function
|
||||
|
||||
doPlayerMove = function
|
||||
clearFractions
|
||||
while true
|
||||
print
|
||||
inp = input("Your move? ")
|
||||
if inp == "0" then
|
||||
showBoard
|
||||
continue
|
||||
end if
|
||||
if inp == "1" then exit
|
||||
ok = true
|
||||
if inp.len != 3 then
|
||||
ok = false
|
||||
else
|
||||
i = inp[0].val
|
||||
j = inp[1].val
|
||||
k = inp[2].val
|
||||
ok = (0 < i < 5) and (0 < j < 5) and (0 < k < 5)
|
||||
end if
|
||||
if not ok then
|
||||
print "Incorrect move, retype it--"
|
||||
else
|
||||
m = 16 * i + 4 * j + k - 20
|
||||
if xa[m] != 0 then
|
||||
print "That square is used, try again."
|
||||
else
|
||||
xa[m] = 1
|
||||
break
|
||||
end if
|
||||
end if
|
||||
end while
|
||||
end function
|
||||
|
||||
selectMove = function(lineIndex, valueToReplace)
|
||||
if lineIndex % 4 <= 1 then a = 1 else a = 2
|
||||
for j in range(a, 5 - a, 5 - 2 * a)
|
||||
if xa[ma[lineIndex][j]] == valueToReplace then
|
||||
xa[ma[lineIndex][j]] = 5
|
||||
m = ma[lineIndex][j]
|
||||
print "Machine takes " + squareName(m)
|
||||
return true
|
||||
end if
|
||||
end for
|
||||
return false
|
||||
end function
|
||||
|
||||
doComputerMove = function
|
||||
// look for lines with two M's and two blanks; add 1/8 to the blank spots
|
||||
for i in range(1, 76)
|
||||
la[i] = xa[ma[i][1]] + xa[ma[i][2]] + xa[ma[i][3]] + xa[ma[i][4]]
|
||||
l = la[i]
|
||||
if l == 10 then
|
||||
for j in range(1, 4)
|
||||
if (xa[ma[i][j]] == 0) then xa[ma[i][j]] = 1/8
|
||||
end for
|
||||
end if
|
||||
end for
|
||||
// ...and if we now find lines containing 4 such spots, or 1 M and 3 such spots,
|
||||
// then pick one of those spots for our move
|
||||
checkForLines
|
||||
for i in range(1, 76)
|
||||
if la[i] == 4/8 or la[i] == 5 + 3/8 then
|
||||
selectMove i, 1/8
|
||||
return true
|
||||
end if
|
||||
end for
|
||||
|
||||
// now look for lines containing 2 Y's, and mark (with 1/8) the blank spots
|
||||
clearFractions
|
||||
for i in range(1, 76)
|
||||
la[i] = xa[ma[i][1]] + xa[ma[i][2]] + xa[ma[i][3]] + xa[ma[i][4]]
|
||||
l = la[i]
|
||||
if l == 2 then
|
||||
for j in range(1, 4)
|
||||
if (xa[ma[i][j]] == 0) then xa[ma[i][j]] = 1 / 8
|
||||
end for
|
||||
end if
|
||||
end for
|
||||
// ...and again, if we find 4 such spots in a row, or 1 player move plus
|
||||
// 3 marked spots, then pick one of those
|
||||
checkForLines
|
||||
for i in range(1, 76)
|
||||
if la[i] == 4/8 or la[i] == 1 + 3/8 then
|
||||
selectMove 1/8
|
||||
return true
|
||||
end if
|
||||
end for
|
||||
|
||||
// do mysterious stuff that depends on the order of lines in ma
|
||||
// in ways I don't understand
|
||||
for k in range(1, 18)
|
||||
p = 0
|
||||
for i in range(4 * k - 3, 4 * k)
|
||||
for j in range(1, 4)
|
||||
p += xa[ma[i][j]]
|
||||
end for
|
||||
end for
|
||||
if p == 4 or p == 9 then
|
||||
for i in range(4 * k - 3, 4 * k)
|
||||
if selectMove(1/8) then return true
|
||||
end for
|
||||
s = 0
|
||||
end if
|
||||
end for
|
||||
|
||||
// look for certain "good" spots in our ya array that are still available
|
||||
clearFractions
|
||||
found = false
|
||||
for z in range(1, 17)
|
||||
if xa[ya[z]] == 0 then
|
||||
found = true
|
||||
break
|
||||
end if
|
||||
end for
|
||||
if not found then
|
||||
// getting desperate, look for any open spot
|
||||
for i in range(1, 64)
|
||||
if xa[i] == 0 then
|
||||
xa[i] = 5
|
||||
print "Machine likes " + squareName(i)
|
||||
return true
|
||||
end if
|
||||
end for
|
||||
print "The game is a draw."
|
||||
return false
|
||||
end if
|
||||
m = ya[z]
|
||||
xa[m] = 5
|
||||
print "Machine moves to " + squareName(m)
|
||||
return true
|
||||
end function
|
||||
|
||||
squareName = function(m)
|
||||
k1 = floor((m - 1) / 16) + 1
|
||||
j2 = m - 16 * (k1 - 1)
|
||||
k2 = floor((j2 - 1) / 4) + 1
|
||||
k3 = m - (k1 - 1) * 16 - (k2 - 1) * 4
|
||||
return str(k1) + k2 + k3
|
||||
end function
|
||||
|
||||
doOneGame = function
|
||||
globals.xa = [null] + [0] * 64 // board state
|
||||
globals.la = [null] + [0] * 76 // line data
|
||||
skipFirst = getYesNo("Do you want to move first") == "no"
|
||||
while true
|
||||
if skipFirst then
|
||||
skipFirst = false
|
||||
else
|
||||
doPlayerMove
|
||||
end if
|
||||
checkForLines
|
||||
machineDone = false
|
||||
// take three passes over the straight lines in the board
|
||||
for j in range(1, 3)
|
||||
for i in range(1, 76)
|
||||
// first pass: check for player win
|
||||
if j == 1 then
|
||||
if la[i] != 4 then continue;
|
||||
print "You win as follows" + " (line " + i + ")"
|
||||
for j in range(1, 4)
|
||||
print squareName(ma[i][j])
|
||||
end for
|
||||
return
|
||||
end if
|
||||
// second pass: check for machine able to win
|
||||
if j == 2 then
|
||||
if la[i] != 15 then continue;
|
||||
for j in range(1, 4)
|
||||
m = ma[i][j]
|
||||
if (xa[m] != 0) then continue;
|
||||
xa[m] = 5
|
||||
break
|
||||
end for
|
||||
print "Machine moves to " + squareName(m) + ", and wins as follows"
|
||||
for j in range(1, 4)
|
||||
print squareName(ma[i][j])
|
||||
end for
|
||||
return
|
||||
end if
|
||||
// third pass: check for player about to win
|
||||
if j == 3 then
|
||||
if la[i] != 3 then continue
|
||||
for j in range(1, 4)
|
||||
m = ma[i][j]
|
||||
if xa[m] != 0 then continue
|
||||
xa[m] = 5
|
||||
print "Nice try, machine moves to " + squareName(m)
|
||||
machineDone = true
|
||||
end for
|
||||
break
|
||||
end if
|
||||
end for
|
||||
end for
|
||||
if (machineDone) then continue
|
||||
|
||||
if not doComputerMove then break
|
||||
end while
|
||||
end function
|
||||
|
||||
|
||||
// Main program
|
||||
if getYesNo("Do you want instructions") == "yes" then
|
||||
print
|
||||
print "The game is tic-tac-toe in a 4 x 4 x 4 cube."
|
||||
print "Each move is indicated by a 3 digit number, with each"
|
||||
print "digit between 1 and 4 inclusive. The digits indicate the"
|
||||
print "level, row, and column, respectively, of the occupied"
|
||||
print "place. "
|
||||
print
|
||||
print "To print the playing board, type 0 (zero) as your move."
|
||||
print "The program will print the board with your moves indi-"
|
||||
print "cated with a (Y), the machine's moves with an (M), and"
|
||||
print "unused squares with a ( )." // "output is on paper."
|
||||
print
|
||||
print "To stop the program run, type 1 as your move."
|
||||
print
|
||||
print
|
||||
end if
|
||||
while true
|
||||
doOneGame
|
||||
print
|
||||
if getYesNo("Do you want to try another game") == "no" then break
|
||||
end while
|
||||
|
||||
|
||||
|
||||
@@ -6,11 +6,13 @@ 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 tictactoe.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 "tictactoe"
|
||||
run
|
||||
run
|
||||
```
|
||||
@@ -6,11 +6,13 @@ 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 tower.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 "tower"
|
||||
run
|
||||
run
|
||||
```
|
||||
|
||||
@@ -4,6 +4,9 @@ Conversion to [MiniScript](https://miniscript.org).
|
||||
|
||||
Ways to play:
|
||||
|
||||
0. "Try-It!" page on the web:
|
||||
Go to https://miniscript.org/tryit/, clear the default program from the source code editor, paste in the contents of train.ms, and click the "Run Script" button.
|
||||
|
||||
1. Command-Line MiniScript:
|
||||
Download for your system from https://miniscript.org/cmdline/, install, and then run the program with a command such as:
|
||||
|
||||
@@ -17,5 +20,3 @@ Download Mini Micro from https://miniscript.org/MiniMicro/, launch, and then cli
|
||||
load "train"
|
||||
run
|
||||
```
|
||||
3. "Try-It!" page on the web:
|
||||
Go to https://miniscript.org/tryit/, clear the default program from the source code editor, paste in the contents of train.ms, and click the "Run Script" button.
|
||||
|
||||
@@ -6,11 +6,13 @@ 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 23matches.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 "23matches"
|
||||
run
|
||||
run
|
||||
```
|
||||
|
||||
@@ -17,6 +17,10 @@ As published in Basic Computer Games (1978):
|
||||
Downloaded from Vintage Basic at
|
||||
http://www.vintage-basic.net/games.html
|
||||
|
||||
#### Known Bugs
|
||||
|
||||
- The original program does not correctly detect identical draws in the first and third position as a double (instead, it counts as a loss). This is probably not intended. Some of the ports fix this, so that any two matches count as a double.
|
||||
|
||||
#### Porting Notes
|
||||
|
||||
(please note any difficulties or challenges in porting here)
|
||||
|
||||
@@ -15,6 +15,8 @@ There are at least two bugs from the original BASIC:
|
||||
1. Code should only allow player to input valid 3D coordinates where every digit is between 1 and 4, but the original code allows any value between 111 and 444 (such as 297, for instance).
|
||||
2. If the player moves first and the game ends in a draw, the original program will still prompt the player for a move instead of calling for a draw.
|
||||
|
||||
Also note that while the file is called qubit.bas (with a "T"), the title shown in the program listing is "QUBIC" (with "C")... and the sample output shows "TIC TAC TOE" instead of either of these.
|
||||
|
||||
---
|
||||
|
||||
As published in Basic Computer Games (1978):
|
||||
|
||||
@@ -193,7 +193,7 @@ function select_move() {
|
||||
}
|
||||
if (j > 5 - a)
|
||||
return false;
|
||||
xa[ma[i][j]] = s;
|
||||
xa[ma[i][j]] = 5;
|
||||
m = ma[i][j];
|
||||
print("MACHINE TAKES");
|
||||
show_square(m);
|
||||
|
||||
Reference in New Issue
Block a user