class PlayerHand
Constants
- MAX_PLAYER_HANDS
Attributes
bet[RW]
blackjack[RW]
cards[RW]
payed[RW]
status[RW]
stood[RW]
Public Class Methods
new(blackjack, bet)
click to toggle source
Calls superclass method
Hand::new
# File lib/blackjack/player_hand.rb, line 15 def initialize(blackjack, bet) super(blackjack) @bet = bet @status = UNKNOWN @payed = false @stood = false end
Public Instance Methods
action?()
click to toggle source
# File lib/blackjack/player_hand.rb, line 93 def action? draw_actions c = Blackjack.getc case c when 'h' hit when 's' stand when 'p' blackjack.split_current_hand when 'd' dbl else clear_draw_hands_action end end
clear_draw_hands_action()
click to toggle source
# File lib/blackjack/player_hand.rb, line 110 def clear_draw_hands_action blackjack.clear blackjack.draw_hands action? end
collect_busted_hand()
click to toggle source
# File lib/blackjack/player_hand.rb, line 75 def collect_busted_hand self.payed = true self.status = LOST blackjack.money -= bet end
collect_lost_hand()
click to toggle source
# File lib/blackjack/player_hand.rb, line 46 def collect_lost_hand blackjack.money -= bet self.status = LOST end
done?()
click to toggle source
# File lib/blackjack/player_hand.rb, line 67 def done? return false unless no_more_actions? self.played = true collect_busted_hand if !payed && busted? true end
draw_actions()
click to toggle source
# File lib/blackjack/player_hand.rb, line 116 def draw_actions actions = [] actions << '(H) Hit' if can_hit? actions << '(S) Stand' if can_stand? actions << '(P) Split' if can_split? actions << '(D) Double' if can_dbl? puts " #{actions.join(' ')}" end
no_more_actions?()
click to toggle source
# File lib/blackjack/player_hand.rb, line 81 def no_more_actions? played || stood || blackjack? || busted? || value(SOFT) == 21 || value(HARD) == 21 end
pay(dealer_hand_value, dealer_busted)
click to toggle source
# File lib/blackjack/player_hand.rb, line 23 def pay(dealer_hand_value, dealer_busted) return if payed self.payed = true player_hand_value = value(SOFT) if player_hand_won?(dealer_busted, dealer_hand_value, player_hand_value) pay_won_hand elsif player_hand_lost?(dealer_hand_value, player_hand_value) collect_lost_hand else self.status = PUSH end end
pay_won_hand()
click to toggle source
# File lib/blackjack/player_hand.rb, line 51 def pay_won_hand self.bet *= 1.5 if blackjack? blackjack.money += bet self.status = WON end
player_hand_lost?(dealer_hand_value, player_hand_value)
click to toggle source
# File lib/blackjack/player_hand.rb, line 38 def player_hand_lost?(dealer_hand_value, player_hand_value) player_hand_value < dealer_hand_value end
player_hand_won?(dealer_busted, dealer_hand_value, player_hand_value)
click to toggle source
# File lib/blackjack/player_hand.rb, line 42 def player_hand_won?(dealer_busted, dealer_hand_value, player_hand_value) dealer_busted || player_hand_value > dealer_hand_value end
process()
click to toggle source
# File lib/blackjack/player_hand.rb, line 85 def process if blackjack.more_hands_to_play? blackjack.play_more_hands else blackjack.play_dealer_hand end end
value(count_method)
click to toggle source
# File lib/blackjack/player_hand.rb, line 57 def value(count_method) total = cards.inject(0) { |sum, card| sum + Card.value(card, count_method, sum) } if count_method == SOFT && total > 21 value(HARD) else total end end