Skip to content

Instantly share code, notes, and snippets.

@bacalj
Forked from anonymous/gist:5924559
Created July 6, 2013 00:42
Show Gist options
  • Save bacalj/5938062 to your computer and use it in GitHub Desktop.
Save bacalj/5938062 to your computer and use it in GitHub Desktop.
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