class DealerHand

Attributes

blackjack[RW]
hide_down_card[RW]

Public Class Methods

new(blackjack) click to toggle source
Calls superclass method Hand::new
# File lib/blackjack/dealer_hand.rb, line 8
def initialize(blackjack)
  super(blackjack)
  @hide_down_card = true
end

Public Instance Methods

both_values() click to toggle source
# File lib/blackjack/dealer_hand.rb, line 54
def both_values
  [value(SOFT), value(HARD)]
end
deal_required_cards() click to toggle source
# File lib/blackjack/dealer_hand.rb, line 46
def deal_required_cards
  soft, hard = both_values
  while soft < 18 && hard < 17
    deal_card
    soft, hard = both_values
  end
end
draw() click to toggle source
# File lib/blackjack/dealer_hand.rb, line 37
def draw
  out = String.new(' ')
  cards.each_with_index do |card, index|
    out << (index == 1 && hide_down_card ? Card.faces[13][0] : card).to_s
    out << ' '
  end
  out << ' ⇒  ' << value(SOFT).to_s
end
play() click to toggle source
# File lib/blackjack/dealer_hand.rb, line 58
def play
  playing = blackjack.need_to_play_dealer_hand?
  self.hide_down_card = false if blackjack? || playing
  deal_required_cards if playing
  self.played = true
  blackjack.pay_hands
end
total_card_value(count_method) click to toggle source
# File lib/blackjack/dealer_hand.rb, line 23
def total_card_value(count_method)
  total = 0
  cards.each_with_index do |card, index|
    next if index == 1 && hide_down_card

    total += Card.value(card, count_method, total)
  end
  total
end
upcard_is_ace?() click to toggle source
# File lib/blackjack/dealer_hand.rb, line 33
def upcard_is_ace?
  cards.first.ace?
end
value(count_method) click to toggle source
# File lib/blackjack/dealer_hand.rb, line 13
def value(count_method)
  total = total_card_value(count_method)

  if count_method == SOFT && total > 21
    value(HARD)
  else
    total
  end
end