Skip to content

Commit

Permalink
Implement value and cards for pair hand
Browse files Browse the repository at this point in the history
  • Loading branch information
camillebaldock committed Sep 8, 2014
1 parent dd9b8c2 commit 7124f2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/hand.rb
Expand Up @@ -46,7 +46,7 @@ def rank
elsif has_two_pairs
has_two_pairs
elsif has_two
{ :type => :pair }
has_two
else
{ :type => :highest }
end
Expand Down Expand Up @@ -87,11 +87,17 @@ def has_two_pairs
end

def has_two
pips_per_occurence[2]
if pips_per_occurence[2]
{
:type => :pair,
:value => pips_per_occurence[2].first,
:cards => pips_per_occurence[1].sort.reverse
}
end
end

def full_house
has_three && has_two
has_three && pips_per_occurence[2]
end

def flush
Expand Down
6 changes: 6 additions & 0 deletions spec/hand_spec.rb
Expand Up @@ -37,6 +37,12 @@
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :pair
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,6]
end
end

context "high card" do
Expand Down

0 comments on commit 7124f2e

Please sign in to comment.