Permalink
Browse files

Implement two pairs

  • Loading branch information...
camillebaldock committed Sep 3, 2014
1 parent f991324 commit b9bd5315afe6c14540cbfe3cfbe36c106b912153
Showing with 19 additions and 0 deletions.
  1. +5 −0 README.md
  2. +7 −0 lib/hand.rb
  3. +7 −0 spec/hand_spec.rb
View
@@ -8,3 +8,8 @@ A “hand” in poker consists of five playing cards drawn from a standard deck.
TBA
## After the video
1) Finish implementing all the poker hands
in a "shameless green" style
View
@@ -26,6 +26,8 @@ def rank
{ :type => :flush }
elsif has_three
{ :type => :three_of_a_kind }
elsif has_two_pairs
{ :type => :two_pair }
elsif has_two
{ :type => :pair }
else
@@ -59,6 +61,11 @@ def has_three
pip_count.values.include?(3)
end
def has_two_pairs
grouped_pip_counts = pip_count.values.group_by { |i| i }
grouped_pip_counts[2] && grouped_pip_counts[2].size == 2
end
def has_two
pip_count.values.include?(2)
end
View
@@ -11,6 +11,9 @@
let(:highest_hand) {
HandParser.new.parse(["4h", "5d", "6d", "7d", "9d"])
}
let(:two_pair_hand) {
HandParser.new.parse(["4h", "4d", "6d", "6h", "9s"])
}
let(:three_of_a_kind_hand) {
HandParser.new.parse(["5h", "5d", "5s", "7d", "8d"])
}
@@ -87,5 +90,9 @@
it "works with a straight with high ace" do
expect(straight_hand_high_ace.rank).to eq ({:type => :straight})
end
it "works with a two pair hand" do
expect(two_pair_hand.rank).to eq ({:type => :two_pair})
end
end
end

0 comments on commit b9bd531

Please sign in to comment.