Permalink
Browse files

Refactor aces as ones logic

  • Loading branch information...
camillebaldock committed Sep 8, 2014
1 parent 3f49c5a commit 70a50fba35fd88803b3ba20d76fe0b21a79193f0
Showing with 15 additions and 9 deletions.
  1. +15 −9 lib/hand.rb
View
@@ -88,15 +88,9 @@ def flush
def straight
card_values = cards.map(&:pips)
- number_aces = card_values.select{|i| i == 14}.count
- if number_aces >= 1
- aces_as_ones = card_values.clone
- aces_as_ones.delete(14)
- number_aces.times do
- aces_as_ones << 1
- end
- consecutive_cards?(card_values) ||
- consecutive_cards?(aces_as_ones)
+ aces_as_ones = aces_as_ones(card_values)
+ if aces_as_ones != card_values
+ consecutive_cards?(aces_as_ones) || consecutive_cards?(card_values)
else
consecutive_cards?(card_values)
end
@@ -110,4 +104,16 @@ def consecutive_cards?(card_values)
array_consecutive_integers?(card_values)
end
+ def aces_as_ones(card_values)
+ number_aces = card_values.select{|i| i == 14}.count
+ result = card_values.clone
+ if number_aces >= 1
+ result.delete(14)
+ number_aces.times do
+ result << 1
+ end
+ end
+ result
+ end
+
end

0 comments on commit 70a50fb

Please sign in to comment.