Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'aces_solution' into cucumber

  • Loading branch information...
commit f3a1d5f3cbd8fa7e6a92760cc414a420a338d990 2 parents 1bd5f52 + 36b54cd
@patmaddox authored
View
8 .autotest
@@ -0,0 +1,8 @@
+begin
+ require 'autotest/growl'
+rescue LoadError
+ $stderr.puts "***************"
+ $stderr.puts "Couldn't load autotest/growl. If you want nifty growl notifications, gem install autotest-growl"
+ $stderr.puts "***************"
+ $stderr.puts ""
+end
View
1  autotest/discover.rb
@@ -0,0 +1 @@
+Autotest.add_discovery { "rspec2" }
View
41 lib/hand.rb
@@ -1,3 +1,44 @@
class Hand
+ def initialize
+ @cards = []
+ end
+ def deal(card)
+ @cards << card
+ end
+
+ def score
+ score_of_non_aces + score_of_aces
+ end
+
+ def score_of_non_aces
+ @cards.reject {|c| c == :ace }.inject(0) do |sum, c|
+ sum += if [:king, :queen, :jack].include?(c)
+ 10
+ else
+ c
+ end
+ end
+ end
+
+ def score_of_aces
+ num_aces = @cards.select {|c| c == :ace }.size
+ if num_aces == 0
+ 0
+ elsif score_of_non_aces > 10 ||
+ (score_of_non_aces == 10 && num_aces > 1)
+ num_aces
+ else
+ 11 + num_aces - 1
+ end
+ end
+
+ def blackjack?
+ score == 21 && @cards.size == 2
+ end
+
+ def bonus?
+ score == 21 &&
+ (@cards.uniq.size == 1 || @cards.max - @cards.min == 2)
+ end
end
View
5 spec/hand_spec.rb
@@ -53,6 +53,11 @@
@hand.deal 9
@hand.should_not be_bonus
end
+
+ it "should not be bonus when dealt 5, 5, 5" do
+ 3.times { @hand.deal 5 }
+ @hand.should_not be_bonus
+ end
it "should be bonus when dealt 6, 7, 8" do
@hand.deal 6
Please sign in to comment.
Something went wrong with that request. Please try again.