Sha256: 06353af5ae32c0b836885b9a5337485a41b2dc5f658ad56cea999dfdb352355e
Contents?: true
Size: 760 Bytes
Versions: 1
Compression:
Stored size: 760 Bytes
Contents
module CardsLib module Standard module Evaluators class BlackjackEvaluator def initialize(cards) @cards = cards @reduced_ace_count = 0 end def worth @worth ||= @cards.map(&:value).inject(:+) if @worth > 21 attempt = reduce_by_ace attempt = reduce_by_ace until @worth < 22 || !attempt end @worth end private def reduce_by_ace if count_aces > @reduced_ace_count @worth -= 10 @reduced_ace_count += 1 true else false end end def count_aces @cards.count {|c| c.rank == "A"} end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cards_lib-0.2.5 | lib/cards_lib/standard/evaluators/blackjack_evaluator.rb |