Permalink
Browse files

Implement value and cards for three of a kind

  • Loading branch information...
camillebaldock committed Sep 8, 2014
1 parent f7f1b76 commit ada5838a2d0d9fd85cc9d0fad6ccc8368e0546f1
Showing with 15 additions and 3 deletions.
  1. +9 −3 lib/hand.rb
  2. +6 −0 spec/hand_spec.rb
View
@@ -42,7 +42,7 @@ def rank
elsif straight
straight
elsif has_three
- { :type => :three_of_a_kind }
+ has_three
elsif has_two_pairs
has_two_pairs
elsif has_two
@@ -77,7 +77,13 @@ def has_four
end
def has_three
- pips_per_occurence[3]
+ if pips_per_occurence[3]
+ {
+ :type => :three_of_a_kind,
+ :value => pips_per_occurence[3].first,
+ :cards => pips_per_occurence[1].sort.reverse,
+ }
+ end
end
def has_two_pairs
@@ -101,7 +107,7 @@ def has_two
end
def full_house
- has_three && pips_per_occurence[2]
+ pips_per_occurence[3] && pips_per_occurence[2]
end
def flush
View
@@ -49,6 +49,12 @@
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :three_of_a_kind
end
+ it "returns the value correctly" do
+ expect(hand.rank.fetch(:value)).to eq 5
+ end
+ it "returns the other cards correctly" do
+ expect(hand.rank.fetch(:cards)).to eq [8,7]
+ end
end
context "four of a kind" do

0 comments on commit ada5838

Please sign in to comment.