-
-
Save bacalj/5938062 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suits = [' of Diamonds' , ' of Hearts', ' of Clubs', ' of Spades'] | |
values = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K' ] | |
deck = [] | |
deck = values.product(suits) | |
deck.shuffle! | |
player = [] | |
dealer = [] | |
2.times do | |
draw_card(deck, dealer) | |
draw_card(deck, player) | |
end | |
def draw_card(deck, hand) | |
hand.push deck.pop | |
end | |
def get_total(hand) | |
total = 0 | |
hand.each do |card| | |
if card[0] == 'A' | |
card.insert(0,11) | |
elsif card[0].to_i == 0 | |
card.insert(0, 10) | |
end | |
total += card[0].to_i | |
end | |
return total | |
end | |
puts '--- BLACKJACK ---'.center(30) | |
puts 'DEALER CARDS:' | |
#-----------------dealer calc------------------------------------- | |
dealer_total = 0 | |
puts "Dealer Total: #{get_total(dealer)}" | |
puts ' ' | |
puts 'YOUR CARDS:' | |
#-----------------player calc------------------------------------- | |
puts "Your Total: #{get_total(player)}" | |
puts ' ' | |
puts ' ' | |
puts '(H)IT or (S)TAY?' | |
puts ' ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment