Class: BlackJack::Dealer

Inherits:
Player
  • Object
show all
Defined in:
lib/black_jack/dealer.rb

Instance Attribute Summary collapse

Attributes inherited from Player

#current_value, #hand, #hand_value, #name

Instance Method Summary collapse

Methods inherited from Player

#bust?, #card_value, #fold_hand, #hit, #take_card, #take_specific_card, #to_s

Constructor Details

#initialize(name = "dealer") ⇒ Dealer

Returns a new instance of Dealer.



10
11
12
13
# File 'lib/black_jack/dealer.rb', line 10

def initialize (name="dealer")
  super(@hand)
  @name = name
end

Instance Attribute Details

#in_the_holeObject (readonly)

This class deals with the special player that follows the rules of a black jack dealer in vegas



8
9
10
# File 'lib/black_jack/dealer.rb', line 8

def in_the_hole
  @in_the_hole
end

Instance Method Details

#dealer_playObject

I am trying(unsuccessfully) to establish the special rules for a deal the dealer should hit at any value of 17 or below



25
26
27
28
29
# File 'lib/black_jack/dealer.rb', line 25

def dealer_play 
 if self.hand_value < 17
   self.hit
 end
end

#show_cards(hand) ⇒ Object

the purpose of this method is to convert the hidden card (in a hash) to a normal card



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/black_jack/dealer.rb', line 32

def show_cards hand
  hand.each do |card|
    if card.class == Hash
      card = card.to_a
      card = card.flatten
      card = card.pop
      hand.delete_if {|x| x.class == Hash}
      hand << card
    end        
  end
end

#show_up_cards(hand) ⇒ Object

this prints out the “up cards” of the dealer so that the player knows the up card



45
46
47
48
49
50
51
52
53
# File 'lib/black_jack/dealer.rb', line 45

def show_up_cards hand
  up_cards = []
  hand.each do |card|
    if card.class != Hash
      up_cards << card      
    end
  end 
puts "The dealer's up-cards are #{up_cards}"
end

#take_card_face_down(deck) ⇒ Object

one of the main differences detween a dealer and a regular player is that the dealer takes one of his cards face down (in a hash)



17
18
19
20
21
22
# File 'lib/black_jack/dealer.rb', line 17

def take_card_face_down deck
  @in_the_hole = Hash.new
  @in_the_hole[:hidden] = deck.deal_a_card
  self.hand << in_the_hole
  self.hand
end