-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
I'm using your class as base for one of my projects (thanks!) and since i did not get my head around your delta_transform method I ended up like this, maybe that's easier?
def straight_flush?
flush? and straight?
end
def straight?
by_face
# I named my version cards, it's the array of cards
temp_cards = cards.dup
if temp_cards[0].face == Card::FACE_VALUES['A'] and temp_cards[1].face != Card::FACE_VALUES['K']
# it's not an ace high straight, so we move the ace to the end
# to test for a low straight
ace = temp_cards.shift
temp_cards << Card.new("L#{Card::SUITS[ace.suit]}")
end
face_value = temp_cards[0].face
temp_cards.each do |c|
return false if face_value != c.face
face_value -= 1
end
true
endI as well added a by_groups func:
def by_groups
# technically, we treat single cards as single group in this loop
pairs = []
until @cards.size == 0
reference = @cards[0]
pair, @cards = @cards.partition { |c| c.face == reference.face}
pairs.push(pair)
end
pairs.sort_by! { |a| [a.size, a[0].face] }.reverse!
pairs.each { |pair| pair.each { |c| @cards << c }}
self
endIt's needed for what I do, but maybe of interest here as well? I could form a pull request if you're interested at all :)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels