Permalink
Browse files

Value and kicker for four of a kind

  • Loading branch information...
camillebaldock committed Sep 8, 2014
1 parent e4e2b09 commit 0f76ee158577c7acf6d700ac4093b03152cfa9c3
Showing with 21 additions and 6 deletions.
  1. +15 −6 lib/hand.rb
  2. +6 −0 spec/hand_spec.rb
View
@@ -34,7 +34,7 @@ def rank
if straight_flush
{ :type => :straight_flush }
elsif has_four
{ :type => :four_of_a_kind }
has_four
elsif full_house
{ :type => :full_house }
elsif flush
@@ -62,21 +62,30 @@ def suit_occurence_count
private
def pips_per_occurence
results_per_occurence_number(cards.map(&:pips))
end
def has_four
pips_occurence_count.include?(4)
if pips_per_occurence[4]
{
:type => :four_of_a_kind,
:value => pips_per_occurence[4].first,
:kicker => pips_per_occurence[1].first
}
end
end
def has_three
pips_occurence_count.include?(3)
end
def has_two_pairs
results_per_occurence = results_per_occurence_number(cards.map(&:pips))
if results_per_occurence[2] && results_per_occurence[2].size == 2
if pips_per_occurence[2] && pips_per_occurence[2].size == 2
{
:type => :two_pair,
:pairs => results_per_occurence[2],
:kicker => results_per_occurence[1].first
:pairs => pips_per_occurence[2],
:kicker => pips_per_occurence[1].first
}
end
end
View
@@ -70,6 +70,12 @@
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :four_of_a_kind
end
it "sets the value correctly" do
expect(hand.rank.fetch(:value)).to eq 5
end
it "sets the kicker correctly" do
expect(hand.rank.fetch(:kicker)).to eq 8
end
end
context "full house" do

0 comments on commit 0f76ee1

Please sign in to comment.