class Hand
Attributes
bet[RW]
cards_in_hand[RW]
choices[RW]
hand_no[RW]
hand_value[RW]
Public Class Methods
new()
click to toggle source
# File lib/mblackjack/hand.rb, line 4 def initialize @hand_no = hand_no @cards_in_hand = [] @bet = 0 @choices = [] @hand_value = 0 end
Public Instance Methods
calc_hand_value()
click to toggle source
Could be improved
# 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