Last night I write a MiniScript implementation of a classic card-betting game. You get two cards, and then bet whether a third card will fall between the first two. Just a bit of fun!
// Acey Deucey
print("Welcome to Acey Deucey!")
print("On each round, you ante $2.")
print("You are then dealt two cards.")
print("Choose how much to bet, then one more card is dealt:")
print(" If the new card falls between the first two, you win 2X your bet!")
print(" If the new card falls outside the first two, you lose your bet.")
print(" If the new card matches either of the first two cards exactly, you lose 2X!")
print
money = 100
cardValues = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "J", "Q", "K"]
suits = ["C", "D", "H", "S"]
deck = []
for cv in cardValues
for suit in suits
deck.push(cv + suit)
end for
end for
deck.shuffle
discard = []
deal = function()
if deck.len == 0 then
globals.deck = discard
globals.discard = []
deck.shuffle
end if
discard.push(deck.pop)
return discard[-1]
end function
cardRank = function(card, aceHigh=false)
card = card[0]
if card == "A" then return 1 + 12*aceHigh
return cardValues.indexOf(card) + 1
end function
getBet = function()
while true
betStr = input("Enter bet (0 to skip, Q to quit): ").upper
if betStr == "Q" then return betStr
if val(betStr) < 0 then
print("A negative bet? Nice try!")
else if val(betStr) > money then
print("You only have " + money + ".")
else
return betStr
end if
end while
end function
while money > 2
globals.money = money - 2
print
print("You have $" + money + ".")
wait
card1 = deal
rank1 = cardRank(card1, false)
card2 = deal
rank2 = cardRank(card2, true)
print(" Card 1: " + card1 + " (Rank: " + rank1 + ")")
wait(0.5)
print(" Card 2: " + card2 + " (Rank: " + rank2 + ")")
wait(0.5)
if rank1 == rank2 then
print("Matched pair: ante lost.")
wait
continue
end if
betStr = getBet
if betStr == "Q" then break
bet = val(betStr)
if betStr <= 0 then
print("Chicken!")
continue
end if
card3 = deal
rank3 = cardRank(card3)
print(" Card 3: " + card3 + " (Rank: " + rank3 + ")")
wait
if rank3 == rank1 or rank3 == rank2 then
print("Ohhh! Double loss!")
globals.money = money - bet * 2
else if rank3 < rank1 and rank3 < rank2 then
print("Too low!")
globals.money = money - bet
else if rank3 > rank1 and rank3 > rank2 then
print("Too high!")
globals.money = money - bet
else
print("You win!")
globals.money = money + bet
end if
wait
end while
if money == 0 then print("You are totally broke.")
if money > 0 then print("You end the day with $" + money + ".")
if money < 0 then print("You owe the bank $" + (-money) + "!")
print("Thanks for playing!")