Permalink
Browse files

Move sort and reversing pips to pips_for_occurence method

  • Loading branch information...
camillebaldock committed Sep 8, 2014
1 parent ea1de56 commit 3a7b0beb9df7373d19b6676bf4130d0bc0fb4a30
Showing with 10 additions and 6 deletions.
  1. +10 −6 lib/hand.rb
View
@@ -52,7 +52,11 @@ def rank
private
def pips_per_occurence
results_per_occurence_number(cards.map(&:pips))
result = results_per_occurence_number(cards.map(&:pips))
result.each do |nb_occurence, pips|
result[nb_occurence] = pips.sort.reverse
end
result
end
def suits_per_occurence
@@ -80,7 +84,7 @@ def compare_value(key, rank, other_rank)
def highest
{
:type => :highest,
:cards => pips_per_occurence[1].sort.reverse
:cards => pips_per_occurence[1]
}
end
@@ -99,7 +103,7 @@ def has_three
{
:type => :three_of_a_kind,
:value => pips_per_occurence[3].first,
:cards => pips_per_occurence[1].sort.reverse,
:cards => pips_per_occurence[1],
}
end
end
@@ -108,7 +112,7 @@ def has_two_pairs
if pips_per_occurence[2] && pips_per_occurence[2].size == 2
{
:type => :two_pair,
:pairs => pips_per_occurence[2].sort.reverse,
:pairs => pips_per_occurence[2],
:cards => pips_per_occurence[1]
}
end
@@ -119,7 +123,7 @@ def has_two
{
:type => :pair,
:value => pips_per_occurence[2].first,
:cards => pips_per_occurence[1].sort.reverse
:cards => pips_per_occurence[1]
}
end
end
@@ -138,7 +142,7 @@ def flush
if suits_per_occurence[5]
{
:type => :flush,
:cards => pips_per_occurence[1].sort.reverse
:cards => pips_per_occurence[1]
}
end
end

0 comments on commit 3a7b0be

Please sign in to comment.