Created
January 14, 2014 19:22
-
-
Save mebezac/8424113 to your computer and use it in GitHub Desktop.
Card Value not using global variable, doesn't work. Card Value, using global does work.
This file contains hidden or 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
#Blackjack | |
$card_values_hash = {"Ace" => 1, "Two" => 2, "Three" => 3, "Four" => 4, "Five" => 5, "Six" => 6, "Seven" => 7, "Eight" => 8, "Nine" => 9, "Ten" => 10, "Jack" => 10, "Queen" => 10, "King" => 10} | |
suits = ["Clubs", "Spades", "Diamonds", "Hearts"] | |
cards = ["Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"] | |
deck = [] | |
player_hand =[] | |
deaker_hand =[] | |
#Create Deck | |
cards.each do |card| | |
suits.each do |suit| | |
deck.push card + " of " + suit | |
end | |
end | |
deck.shuffle! | |
def card_value (card) | |
$card_values_hash[card] | |
end | |
puts card_value "King" | |
# prints 10, which is correct. |
This file contains hidden or 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
#Blackjack | |
card_values_hash = {"Ace" => 1, "Two" => 2, "Three" => 3, "Four" => 4, "Five" => 5, "Six" => 6, "Seven" => 7, "Eight" => 8, "Nine" => 9, "Ten" => 10, "Jack" => 10, "Queen" => 10, "King" => 10} | |
suits = ["Clubs", "Spades", "Diamonds", "Hearts"] | |
cards = ["Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"] | |
deck = [] | |
player_hand =[] | |
deaker_hand =[] | |
#Create Deck | |
cards.each do |card| | |
suits.each do |suit| | |
deck.push card + " of " + suit | |
end | |
end | |
deck.shuffle! | |
def card_value (card) | |
card_values_hash[card] | |
end | |
puts card_value "King" | |
# Error: card_value.rb:20:in `card_value': undefined local variable or method `card_values_hash' for main:Object (NameError) | |
# from card_value.rb:22:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment