mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-12 15:50:20 -08:00
Added MiniScript implementation of Bombardment and Bombs Away.
Also fixed a minor issue with Blackjack.
This commit is contained in:
@@ -11,6 +11,8 @@ playerMoney = [0]*8 // total $ for each player (T)
|
||||
roundWinnings = [0]*7 // total $ won/lost this hand for each player (S)
|
||||
betPerHand = [0]*15 // bet for each hand (B)
|
||||
|
||||
cardNames = " A 2 3 4 5 6 7 8 9 10 J Q K".split
|
||||
|
||||
reshuffle = function
|
||||
print "Reshuffling"
|
||||
globals.deck = range(1,13)*4
|
||||
@@ -23,6 +25,12 @@ getCard = function
|
||||
return deck.pop
|
||||
end function
|
||||
|
||||
// Function to get a name for the given card, preceded by "a" or "an"
|
||||
a = function(cardNum)
|
||||
article = "a" + "n" * (cardNum == 1 or cardNum == 8)
|
||||
return article + " " + cardNames[cardNum]
|
||||
end function
|
||||
|
||||
// Function to evaluate the given hand. Total is usually put into
|
||||
// handValue(handNum). Totals have the following meaning:
|
||||
// 2-10...Hard 2-10
|
||||
@@ -123,7 +131,7 @@ playOneRound = function
|
||||
// Test for dealer blackjack
|
||||
if (dealerCard0==1 and dealerCard1 > 9) or
|
||||
(dealerCard0 > 9 and dealerCard1==1) then
|
||||
print; print "Dealer has a " + cardNames[dealerCard1] + " in the hole for Blackjack"
|
||||
print; print "Dealer has " + a(dealerCard1) + " in the hole for Blackjack"
|
||||
for i in range(0, numPlayers)
|
||||
handValue[i] = evalHand(i)
|
||||
end for
|
||||
@@ -144,11 +152,11 @@ playOneRound = function
|
||||
if hands[i] or hands[i+8] then anyLeft = true
|
||||
end for
|
||||
if not anyLeft then
|
||||
print "Dealer had a " + cardNames[hands[numPlayers][1]] + " concealed."
|
||||
print "Dealer had " + a(hands[numPlayers][1]) + " concealed."
|
||||
else
|
||||
// Play dealer's hand.
|
||||
dispTotal = displayTotal(handValue[numPlayers])
|
||||
print "Dealer has a " + cardNames[hands[numPlayers][1]] + " concealed" +
|
||||
print "Dealer has " + a(hands[numPlayers][1]) + " concealed" +
|
||||
" for a total of " + dispTotal + "."
|
||||
while handValue[numPlayers] > 0 and dispTotal <= 16
|
||||
card = getCard
|
||||
@@ -187,7 +195,7 @@ playHand = function(handNum, prompt=null, allowSplit=true)
|
||||
handValue[handNum] = evalHand(handNum)
|
||||
if choice == "D" then betPerHand[handNum] *= 2
|
||||
card = getCard
|
||||
print "Received a " + cardNames[card], " "
|
||||
print "Received " + a(card), " "
|
||||
hands[handNum].push card
|
||||
handValue[handNum] = evalHand(handNum)
|
||||
if handValue[handNum] < 0 then
|
||||
@@ -209,10 +217,10 @@ playHand = function(handNum, prompt=null, allowSplit=true)
|
||||
hands[hand2] = [hands[handNum].pop]
|
||||
betPerHand[hand2] = betPerHand[handNum]
|
||||
card = getCard
|
||||
print "First hand receives a " + cardNames[card]
|
||||
print "First hand receives " + a(card)
|
||||
hands[handNum].push card
|
||||
card = getCard
|
||||
print "Second hand receives a " + cardNames[card]
|
||||
print "Second hand receives " + a(card)
|
||||
hands[hand2].push card
|
||||
if card1 != 1 then
|
||||
// Now play the two hands
|
||||
@@ -252,9 +260,7 @@ tallyResults = function
|
||||
print
|
||||
end function
|
||||
|
||||
// Main program starts here // (Line 1500)
|
||||
// Initialize
|
||||
cardNames = "n A 2 3 4 5 6 7 8 9 10 J Q K".split
|
||||
// Main program starts here
|
||||
|
||||
if getYesNo("Do you want instructions? ") == "Y" then
|
||||
print "This is the game of 21. As many as 7 players may play the"
|
||||
|
||||
16
00_Alternate_Languages/11_Bombardment/MiniScript/README.md
Normal file
16
00_Alternate_Languages/11_Bombardment/MiniScript/README.md
Normal 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 bombardment.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 BASIC program. Then, at the Mini Micro command prompt, enter:
|
||||
|
||||
load "bombardment"
|
||||
run
|
||||
101
00_Alternate_Languages/11_Bombardment/MiniScript/bombardment.ms
Normal file
101
00_Alternate_Languages/11_Bombardment/MiniScript/bombardment.ms
Normal file
@@ -0,0 +1,101 @@
|
||||
print " "*33 + "Bombardment"
|
||||
print " "*15 + "Creative Computing Morristown, New Jersey"
|
||||
print; print; print
|
||||
print "You are on a battlefield with 4 platoons and you"
|
||||
print "have 25 outposts available where they may be placed."
|
||||
print "You can only place one platoon at any one outpost."
|
||||
print "The computer does the same with its four platoons."
|
||||
print
|
||||
print "The object of the game is to fire missiles at the"
|
||||
print "outposts of the computer. It will do the same to you."
|
||||
print "The one who destroys all four of the enemy's platoons"
|
||||
print "first is the winner."
|
||||
print
|
||||
print "Good luck... and tell us where you want the bodies sent!"
|
||||
print
|
||||
input "(Press Return.)" // (so user can read the above)
|
||||
print
|
||||
print "Tear off matrix and use it to check off the numbers."
|
||||
for i in range(1,5); print; end for
|
||||
memory = [] // records computer's guesses
|
||||
for row in range(1,5)
|
||||
for i in range(row*5-4, row*5)
|
||||
print (" " + i)[-6:], ""
|
||||
end for
|
||||
print
|
||||
end for
|
||||
print
|
||||
|
||||
// Define a helper function to pick a random position (1-25)
|
||||
// that is not already in the given list.
|
||||
pickOutpost = function(excludingThese)
|
||||
while true
|
||||
pick = floor(rnd * 25) + 1
|
||||
if excludingThese.indexOf(pick) == null then return pick
|
||||
end while
|
||||
end function
|
||||
|
||||
// Choose the computer's four positions.
|
||||
computerOutposts = []
|
||||
for i in range(1,4)
|
||||
computerOutposts.push pickOutpost(computerOutposts)
|
||||
end for
|
||||
|
||||
playerOutposts = []
|
||||
while playerOutposts.len != 4
|
||||
inp = input("What are your four positions? ")
|
||||
inp = inp.replace(", ", " ").replace(",", " ")
|
||||
inp = inp.split
|
||||
for pos in inp
|
||||
pos = pos.val
|
||||
playerOutposts.push pos
|
||||
if pos < 1 or pos > 25 then playerOutposts=[]
|
||||
end for
|
||||
end while
|
||||
|
||||
// Main loop.
|
||||
while true
|
||||
// player's attack
|
||||
pos = input("Where do you wish to fire your missile? ").val
|
||||
if computerOutposts.indexOf(pos) == null then
|
||||
print "Ha, ha you missed. My turn now:"
|
||||
else
|
||||
print "You got one of my outposts!"
|
||||
computerOutposts.remove computerOutposts.indexOf(pos)
|
||||
left = computerOutposts.len
|
||||
if left == 3 then
|
||||
print "One down, three to go."
|
||||
else if left == 2 then
|
||||
print "Two down, two to go."
|
||||
else if left == 3 then
|
||||
print "Three down, one to go."
|
||||
else
|
||||
print "You got me, I'm going fast. ButI'll get you when"
|
||||
print "My transisto&s recup%ra*e!"
|
||||
break
|
||||
end if
|
||||
end if
|
||||
|
||||
// computer's attack
|
||||
pos = pickOutpost(memory)
|
||||
memory.push pos
|
||||
if playerOutposts.indexOf(pos) == null then
|
||||
print "I missed you, you dirty rat. I picked " + pos + ". Your turn:"
|
||||
else
|
||||
playerOutposts.remove playerOutposts.indexOf(pos)
|
||||
left = playerOutposts.len
|
||||
if left == 0 then
|
||||
print "You're dead. Your last outpost was at " + pos + ". Ha, ha, ha."
|
||||
print "Better luck next time."
|
||||
break
|
||||
end if
|
||||
print "I got you. It won't be long now. Post " + pos + " was hit."
|
||||
if left == 3 then
|
||||
print "You have only three outposts left."
|
||||
else if left == 2 then
|
||||
print "You have only two outposts left."
|
||||
else if left == 1 then
|
||||
print "You have only one outpost left."
|
||||
end if
|
||||
end if
|
||||
end while
|
||||
16
00_Alternate_Languages/12_Bombs_Away/MiniScript/README.md
Normal file
16
00_Alternate_Languages/12_Bombs_Away/MiniScript/README.md
Normal 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 bombsaway.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 BASIC program. Then, at the Mini Micro command prompt, enter:
|
||||
|
||||
load "bombsaway"
|
||||
run
|
||||
112
00_Alternate_Languages/12_Bombs_Away/MiniScript/bombsaway.ms
Normal file
112
00_Alternate_Languages/12_Bombs_Away/MiniScript/bombsaway.ms
Normal file
@@ -0,0 +1,112 @@
|
||||
|
||||
getNum = function(prompt, maxVal=5)
|
||||
while true
|
||||
num = floor(input(prompt + "? ").val)
|
||||
if num > 0 and num <= maxVal then return num
|
||||
print "Try again..."
|
||||
end while
|
||||
end function
|
||||
|
||||
showReturn = function
|
||||
print "You made it through tremendous flak!!"
|
||||
end function
|
||||
|
||||
showShotDown = function
|
||||
print "* * * * boom * * * *"
|
||||
print "You have been shot down....."
|
||||
print "Dearly beloved, we are gathered here today to pay our"
|
||||
print "last tribute..."
|
||||
end function
|
||||
|
||||
showSuccess = function
|
||||
print "Direct hit!!!! " + floor(100*rnd) + " killed."
|
||||
print "Mission successful."
|
||||
end function
|
||||
|
||||
// Function to calculate the mission result for all nations except Japan.
|
||||
doNonJapanResult = function
|
||||
print
|
||||
d = input("How many missions have you flown? ").val
|
||||
while d >= 160
|
||||
print "Missions, not miles..."
|
||||
print "150 missions is high even for old-timers."
|
||||
d = input("Now then, how many missions have you flown? ").val
|
||||
end while
|
||||
print
|
||||
if d >= 100 then print "That's pushing the odds!"
|
||||
if d < 25 then print "Fresh out of training, eh?"
|
||||
print
|
||||
if d >= 160 * rnd then
|
||||
showSuccess
|
||||
else
|
||||
print "Missed target by " + floor(2+30*rnd) + " miles!"
|
||||
print "Now you're really in for it !!"; print
|
||||
r = getNum("Does the enemy have guns(1), missiles(2), or both(3)")
|
||||
print
|
||||
if r != 2 then
|
||||
s = input("What's the percent hit rate of enemy gunners (10 to 50)? ").val
|
||||
if s<10 then
|
||||
print "You lie, but you'll pay..."
|
||||
showShotDown
|
||||
return
|
||||
end if
|
||||
end if
|
||||
print
|
||||
print
|
||||
if r > 1 then t = 35 else t = 0
|
||||
if s + t > 100 * rnd then
|
||||
showShotDown
|
||||
else
|
||||
showReturn
|
||||
end if
|
||||
end if
|
||||
end function
|
||||
|
||||
s = 0 // hit rate of enemy gunners
|
||||
r = 0 // whether enemy has guns(1), missiles(2), or both(3)
|
||||
|
||||
// Main Loop
|
||||
while true
|
||||
print "You are a pilot in a World War II bomber."
|
||||
a = getNum("What side -- Italy(1), Allies(2), Japan(3), Germany(4)", 4)
|
||||
|
||||
if a == 1 then // Italy
|
||||
b = getNum("Your target -- Albania(1), Greece(2), North Africa(3)")
|
||||
print
|
||||
print ["Should be easy -- you're flying a nazi-made plane.",
|
||||
"Be careful!!!", "You're going for the oil, eh?"][b-1]
|
||||
doNonJapanResult
|
||||
|
||||
else if a == 2 then // Allies
|
||||
g = getNum("Aircraft -- Liberator(1), B-29(2), B-17(3), Lancaster(4)", 4)
|
||||
print ["You've got 2 tons of bombs flying for Ploesti.",
|
||||
"You're dumping the A-bomb on Hiroshima.",
|
||||
"You're chasing the Aismark in the North Sea.",
|
||||
"You're busting a German heavy water plant in the Ruhr."][g-1]
|
||||
doNonJapanResult
|
||||
|
||||
else if a == 3 then // Japan (different logic than all others)
|
||||
print "You're flying a kamikaze mission over the USS Lexington."
|
||||
isFirst = input("Your first kamikaze mission(y or n)? ").lower
|
||||
if isFirst and isFirst[0] == "n" then
|
||||
s = 0
|
||||
showReturn
|
||||
else
|
||||
print
|
||||
if rnd > 0.65 then showSuccess else showShotDown
|
||||
end if
|
||||
|
||||
else // Germany
|
||||
m = getNum("A nazi, eh? Oh well. Are you going for Russia(1)," +
|
||||
char(13) + "England(2), or France(3)")
|
||||
print ["You're nearing Stalingrad.",
|
||||
"Nearing London. Be careful, they've got radar.",
|
||||
"Nearing Versailles. Duck soup. They're nearly defenseless."][m-1]
|
||||
doNonJapanResult
|
||||
end if
|
||||
|
||||
print; print; print; another = input("Another mission (y or n)? ").lower
|
||||
if not another or another[0] != "y" then
|
||||
print "Chicken !!!" ; print ; break
|
||||
end if
|
||||
end while
|
||||
@@ -19,6 +19,7 @@ http://www.vintage-basic.net/games.html
|
||||
#### Porting Notes
|
||||
|
||||
The program makes extensive use of the assumption that a boolean expression evaluates to **-1** for true. This was the case in some classic BASIC environments but not others; and it is not the case in [JS Basic](https://troypress.com/wp-content/uploads/user/js-basic/index.html), leading to nonsensical results. In an environment that uses **1** instead of **-1** for truth, you would need to negate the boolean expression in the following lines:
|
||||
- 10
|
||||
- 570
|
||||
- 590
|
||||
- 2220
|
||||
|
||||
@@ -13,6 +13,10 @@ As published in Basic Computer Games (1978):
|
||||
Downloaded from Vintage Basic at
|
||||
http://www.vintage-basic.net/games.html
|
||||
|
||||
#### Known Bugs
|
||||
|
||||
- If you play as Japan and say it is not your first mission, it is impossible to complete your mission; the only possible outcomes are "you made it through" or "boom". Moreover, the odds of each outcome depend on a variable (R) that is only set if you played a previous mission as a different side. It's possible this is an intentional layer of complexity meant to encourage repeat play, but it's more likely just a logical error.
|
||||
|
||||
#### Porting Notes
|
||||
|
||||
(please note any difficulties or challenges in porting here)
|
||||
|
||||
Reference in New Issue
Block a user