You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
defstraight_flush?flush?andstraight?enddefstraight?by_face# I named my version cards, it's the array of cardstemp_cards=cards.dupiftemp_cards[0].face == Card::FACE_VALUES['A']andtemp_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 straightace=temp_cards.shifttemp_cards << Card.new("L#{Card::SUITS[ace.suit]}")endface_value=temp_cards[0].facetemp_cards.eachdo |c|
returnfalseifface_value != c.faceface_value -= 1endtrueend
I as well added a by_groups func:
defby_groups# technically, we treat single cards as single group in this looppairs=[]until@cards.size == 0reference=@cards[0]pair,@cards=@cards.partition{ |c| c.face == reference.face}pairs.push(pair)endpairs.sort_by!{ |a| [a.size,a[0].face]}.reverse!pairs.each{ |pair| pair.each{ |c| @cards << c}}selfend
It'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 :)
The text was updated successfully, but these errors were encountered:
Hi @shredding. I agree that the delta_transform method is crazy confusing although I documented it much better in late December to make it more understandable (4c2402b).
I'm sure it could be changed, but the straight? method as you've written it doesn't match the method contract of returning an array in the format [[5, high_card], arranged_hand].
I think you're version would be slower because it creates more objects. The current versions of straight and delta_transform use regular expressions which I think are faster.
However, yours is more approachable. If you could get it to pass the test suite and test/integration/test_a_million_hands.rb (see comment at top of file for how to run). Then I think I would put it in.
I looked at by_groups quickly but I do not understand what it is doing. You would need to post examples.
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?I as well added a
by_groups
func:It'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 :)
The text was updated successfully, but these errors were encountered: