Class: Hand
- Inherits:
-
Object
- Object
- Hand
- Defined in:
- lib/mblackjack/hand.rb
Instance Attribute Summary collapse
-
#bet ⇒ Object
Returns the value of attribute bet.
-
#cards_in_hand ⇒ Object
Returns the value of attribute cards_in_hand.
-
#choices ⇒ Object
Returns the value of attribute choices.
-
#hand_no ⇒ Object
Returns the value of attribute hand_no.
-
#hand_value ⇒ Object
Returns the value of attribute hand_value.
Instance Method Summary collapse
-
#calc_hand_value ⇒ Object
Could be improved.
-
#initialize ⇒ Hand
constructor
A new instance of Hand.
Constructor Details
#initialize ⇒ Hand
Returns a new instance of Hand.
4 5 6 7 8 9 10 |
# File 'lib/mblackjack/hand.rb', line 4 def initialize @hand_no = hand_no @cards_in_hand = [] @bet = 0 @choices = [] @hand_value = 0 end |
Instance Attribute Details
#bet ⇒ Object
Returns the value of attribute bet.
2 3 4 |
# File 'lib/mblackjack/hand.rb', line 2 def bet @bet end |
#cards_in_hand ⇒ Object
Returns the value of attribute cards_in_hand.
2 3 4 |
# File 'lib/mblackjack/hand.rb', line 2 def cards_in_hand @cards_in_hand end |
#choices ⇒ Object
Returns the value of attribute choices.
2 3 4 |
# File 'lib/mblackjack/hand.rb', line 2 def choices @choices end |
#hand_no ⇒ Object
Returns the value of attribute hand_no.
2 3 4 |
# File 'lib/mblackjack/hand.rb', line 2 def hand_no @hand_no end |
#hand_value ⇒ Object
Returns the value of attribute hand_value.
2 3 4 |
# File 'lib/mblackjack/hand.rb', line 2 def hand_value @hand_value end |
Instance Method Details
#calc_hand_value ⇒ Object
Could be improved
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mblackjack/hand.rb', line 13 def calc_hand_value @hand_value = 0 cards_in_hand.each_with_index do |c,ind| if c != "ace" value = Deck.card_values.fetch(c) @hand_value += value elsif c == "ace" && cards_in_hand[ind -1] == "ace" value = Deck.card_values.fetch(c)[0] @hand_value += value elsif c == "ace" value = Deck.card_values.fetch(c)[1] @hand_value += value end end if @hand_value > 21 and cards_in_hand.include?("ace") @hand_value -= 10 end end |