class Blackjack::Hand::PlayerHand
Attributes
bet[R]
Public Class Methods
new(player, bet, cards)
click to toggle source
Calls superclass method
Blackjack::Hand::BaseHand::new
# File lib/blackjack/hand/player_hand.rb, line 6 def initialize(player, bet, cards) @player = player @bet = bet super(cards) end
Public Instance Methods
append(card)
click to toggle source
Calls superclass method
Blackjack::Hand::BaseHand#append
# File lib/blackjack/hand/player_hand.rb, line 33 def append(card) raise Errors::HandError.new('Unable to append: hand is marked as stand') if stand? super(card) end
can_double?()
click to toggle source
# File lib/blackjack/hand/player_hand.rb, line 51 def can_double? can_hit? && @player.can_afford?(bet) end
can_hit?()
click to toggle source
# File lib/blackjack/hand/player_hand.rb, line 47 def can_hit? can_stand? end
can_split?()
click to toggle source
# File lib/blackjack/hand/player_hand.rb, line 55 def can_split? can_double? && state == :initial && @cards.first.equal_by_rank?(@cards.last) end
can_stand?()
click to toggle source
# File lib/blackjack/hand/player_hand.rb, line 43 def can_stand? !(stand? || busted?) end
double_bet()
click to toggle source
# File lib/blackjack/hand/player_hand.rb, line 72 def double_bet @bet *= 2 end
options()
click to toggle source
# File lib/blackjack/hand/player_hand.rb, line 61 def options return [] if busted? || stand? [].tap do |options| options << :hit if can_hit? options << :stand if can_stand? options << :double if can_double? options << :split if can_split? end end
playable?()
click to toggle source
# File lib/blackjack/hand/player_hand.rb, line 39 def playable? !(stand? || busted?) && value < 21 end
split(first_card, second_card)
click to toggle source
# File lib/blackjack/hand/player_hand.rb, line 13 def split(first_card, second_card) raise Errors::HandError.new('Unable to split') unless can_split? last_card = @cards.pop @cards.push(first_card) PlayerHand.new(@player, @bet, [ last_card, second_card ]) end
stand()
click to toggle source
# File lib/blackjack/hand/player_hand.rb, line 21 def stand raise Errors::HandError.new('Unable to stand') unless can_stand? @state = :stand self end
stand?()
click to toggle source
# File lib/blackjack/hand/player_hand.rb, line 29 def stand? @state == :stand end