Module: PlayerHandActions

Included in:
PlayerHand
Defined in:
lib/blackjack/player_hand_actions.rb

Instance Method Summary collapse

Instance Method Details

#can_dbl?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/blackjack/player_hand_actions.rb', line 12

def can_dbl?
  return false if blackjack.money < blackjack.all_bets + bet

  !(stood || cards.size != 2 || blackjack?)
end

#can_hit?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/blackjack/player_hand_actions.rb', line 22

def can_hit?
  !(played || stood || value(:hard) == 21 || blackjack? || busted?)
end

#can_split?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
# File 'lib/blackjack/player_hand_actions.rb', line 4

def can_split?
  return false if stood || blackjack.player_hands.size >= PlayerHand::MAX_PLAYER_HANDS

  return false if blackjack.money < blackjack.all_bets + bet

  cards.size == 2 && cards.first.value == cards.last.value
end

#can_stand?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/blackjack/player_hand_actions.rb', line 18

def can_stand?
  !(stood || busted? || blackjack?)
end

#dblObject



37
38
39
40
41
42
43
# File 'lib/blackjack/player_hand_actions.rb', line 37

def dbl
  deal_card

  self.played = true
  self.bet *= 2
  process if done?
end

#hitObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/blackjack/player_hand_actions.rb', line 26

def hit
  deal_card

  if done?
    process
  else
    blackjack.draw_hands
    blackjack.current_player_hand.action?
  end
end

#standObject



45
46
47
48
49
# File 'lib/blackjack/player_hand_actions.rb', line 45

def stand
  self.stood = true
  self.played = true
  process
end