34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/acpc_poker_types/pile_of_cards.rb', line 34
def to_poker_hand_description
case to_poker_hand_key
when :royal_flush
'royal flush'
when :straight_flush
"#{Rank.new(to_poker_hand_strength - POKER_HAND_STRENGTHS[:straight_flush] + 3).to_sym}-high straight flush"
when :four_of_a_kind
rank_with_quad = largest_rank(4)
m = "quad #{ActiveSupport::Inflector.pluralize(rank_with_quad.to_sym.to_s)}"
if length > 4
kicker = remaining_cards(rank_with_quad, 4).largest_rank
"#{m} with #{kicker.to_sym} kicker"
else
m
end
when :full_house
rank_with_trip = largest_rank(3)
rank_with_pair = remaining_cards(rank_with_trip, -1).largest_rank 2
"#{ActiveSupport::Inflector.pluralize(rank_with_trip.to_sym.to_s)} full of #{ActiveSupport::Inflector.pluralize(rank_with_pair.to_sym.to_s)}"
when :flush
flush_with_largest_rank = nil
largest_rank_so_far = -1
Suit.every_suit do |suit|
if count { |c| c.suit == suit } >= 5
r = largest_rank 1, [suit]
if r > largest_rank_so_far
flush_with_largest_rank = suit
largest_rank_so_far = r
end
end
end
cards = all_cards flush_with_largest_rank
r1 = cards.largest_rank
cards = cards.remaining_cards(r1)
r2 = cards.largest_rank
cards = cards.remaining_cards(r2)
r3 = cards.largest_rank
cards = cards.remaining_cards(r3)
r4 = cards.largest_rank
cards = cards.remaining_cards(r4)
r5 = cards.largest_rank
"#{r1.to_sym}, #{r2.to_sym}, #{r3.to_sym}, #{r4.to_sym}, #{r5.to_sym} flush"
when :straight
"#{Rank.new(to_poker_hand_strength - POKER_HAND_STRENGTHS[:straight] + 3).to_sym}-high straight"
when :three_of_a_kind
r = largest_rank 3
m = "trip #{ActiveSupport::Inflector.pluralize(r.to_sym.to_s)}"
if length > 3
cards = remaining_cards(r, 3)
r1 = cards.largest_rank
m += " with #{r1.to_sym}"
if length > 4
cards = cards.remaining_cards r1
r2 = cards.largest_rank
m += " and #{r2.to_sym}"
end
end
m
when :two_pair
first_pair = largest_rank 2
cards = remaining_cards first_pair, -1
second_pair = cards.largest_rank 2
m = "#{ActiveSupport::Inflector.pluralize(first_pair.to_sym.to_s)} and #{ActiveSupport::Inflector.pluralize(second_pair.to_sym.to_s)}"
if length > 4
cards = cards.remaining_cards second_pair, -1
"#{m} with #{cards.largest_rank.to_sym} kicker"
else
m
end
when :one_pair
pair = largest_rank 2
m = "pair of #{ActiveSupport::Inflector.pluralize(pair.to_sym.to_s)}"
if length > 2
cards = remaining_cards pair, -1
r1 = cards.largest_rank
m += " with #{r1.to_sym}"
if length > 3
cards = cards.remaining_cards r1, -1
r2 = cards.largest_rank
if length > 4
cards = cards.remaining_cards r2, -1
r3 = cards.largest_rank
m += ", #{r2.to_sym}, and #{r3.to_sym}"
else
m += " and #{r2.to_sym}"
end
end
end
m
when :high_card
cards = self
hand = [5, length].min.times.inject([]) do |h, i|
c = cards.largest_rank
h << c.to_sym
cards = cards.remaining_cards(c, -1)
h
end
if length == 1
"#{hand.first}"
elsif length == 2
"#{hand.first} and #{hand.last}"
else
"#{hand[0..-2].join(', ')}, and #{hand.last}"
end
end
end
|