Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'aces_solution' into cucumber
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Autotest.add_discovery { "rspec2" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters