1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
//! Contains all Poker hand evaluators
//!
//! Please note that all evaluators will error if the appropriate number of cards are given or if
//! any duplicate cards are detected.
pub use EvaluatorError;
/// An evaluator for high hands
///
/// This evaluator is typically used for games like Texas Hold'em, Five Card Draw, and Stud.
///
/// ## Examples
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::high_evaluator};
///
/// let hand = Card::vec_from_str("5h5s").unwrap();
/// let board = Card::vec_from_str("2dTdKs5dAc").unwrap();
///
/// let mut all_cards = hand.clone();
/// all_cards.extend(board.iter());
///
/// let rank = high_evaluator::evaluate_hand(&all_cards).unwrap();
///
/// assert_eq!(rank.description.as_ref().unwrap(), "Trip 5s");
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::high_evaluator};
///
/// let hand = Card::vec_from_str("KhAs").unwrap();
/// let board = Card::vec_from_str("2cQdKs5dAd").unwrap();
///
/// let mut all_cards = hand.clone();
/// all_cards.extend(board.iter());
///
/// let rank = high_evaluator::evaluate_hand(&all_cards).unwrap();
///
/// assert_eq!(rank.description.as_ref().unwrap(), "Two Pair of Aces and Kings");
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::high_evaluator};
///
/// let mut hero_hand = Card::vec_from_str("KhQc").unwrap();
/// let mut villan_hand = Card::vec_from_str("Ac2c").unwrap();
/// let board = Card::vec_from_str("AhKsQs9c2h").unwrap();
///
/// hero_hand.extend(board.iter());
/// villan_hand.extend(board.iter());
///
/// let hero_rank = high_evaluator::evaluate_hand(&hero_hand).unwrap();
/// let villan_rank = high_evaluator::evaluate_hand(&villan_hand).unwrap();
///
/// assert_eq!(hero_rank.description.as_ref().unwrap(), "Two Pair of Kings and Queens");
/// assert_eq!(villan_rank.description.as_ref().unwrap(), "Two Pair of Aces and 2s");
///
/// assert!(hero_rank < villan_rank); // Villan's hand is better than the hero's
/// ```
/// An evaluator for 2-7 lowball hands
///
/// This evaluator is typically used for games like 2-7 Lowball Draw.
///
/// ## Examples
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::low_27_evaluator};
///
/// let hand = Card::vec_from_str("2dTd3s5sAc").unwrap();
///
/// let rank = low_27_evaluator::evaluate_hand(&hand).unwrap();
///
/// assert_eq!(rank.description.as_ref().unwrap(), "Ace High");
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::low_27_evaluator};
///
/// let hand = Card::vec_from_str("2c4dKs2dKd").unwrap();
///
/// let rank = low_27_evaluator::evaluate_hand(&hand).unwrap();
///
/// assert_eq!(rank.description.as_ref().unwrap(), "Two Pair of Kings and 2s");
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::low_27_evaluator};
///
/// let hero_hand = Card::vec_from_str("6h7h2s3cTd").unwrap();
/// let villan_hand = Card::vec_from_str("2c3s4s5s6d").unwrap();
///
/// let hero_rank = low_27_evaluator::evaluate_hand(&hero_hand).unwrap();
/// let villan_rank = low_27_evaluator::evaluate_hand(&villan_hand).unwrap();
///
/// assert_eq!(hero_rank.description.as_ref().unwrap(), "10 High");
/// assert_eq!(villan_rank.description.as_ref().unwrap(), "6 High Straight");
///
/// assert!(hero_rank > villan_rank); // Hero's hand is better than the villan's
/// ```
// pub mod low_a5_evaluator;
/// An evaluator for Omaha High hands
///
/// The evaluator requires that the player has at least 4 cards and the board has at least 3
/// cards. In Omaha and Omaha-variants, the player is required to use only 2 cards from their
/// hand and 3 from the board. This evaluator permutates through these combinations in parallel
/// with the help of map-reduce.
///
/// Some games that can make use of this evaluator include but are not limited to Omaha, Omaha 8
/// (Hi-Lo), Big O, and Dramaha.
///
/// ## Examples
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::omaha_hi_evaluator};
///
/// let hand = Card::vec_from_str("2cAsAcKc").unwrap();
/// let board = Card::vec_from_str("Ks2sTd8h7d").unwrap();
///
/// let rank = omaha_hi_evaluator::evaluate_hand(&hand, &board).unwrap();
///
/// // Notice: Even though we have Aces in our hand, we can only use 2 cards from out hand to
/// // make the best hand (e.g. the king and the deuce pair with the board).
/// assert_eq!(rank.description.as_ref().unwrap(), "Two Pair of Kings and 2s");
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::omaha_hi_evaluator};
///
/// let hand = Card::vec_from_str("AcKhKsTd").unwrap();
/// let board = Card::vec_from_str("Tc5c3s6cQc").unwrap();
///
/// let rank = omaha_hi_evaluator::evaluate_hand(&hand, &board).unwrap();
///
/// // Notice: Even though we have the Ace of Clubs in out hand, we do not have a flush, as we
/// // need another club within our hand.
/// assert_eq!(rank.description.as_ref().unwrap(), "Pair of Kings");
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::omaha_hi_evaluator};
///
/// let hero_hand = Card::vec_from_str("5s6c9s7c").unwrap();
/// let villan_hand = Card::vec_from_str("AhKdAsTh").unwrap();
/// let board = Card::vec_from_str("8hTcAdQs6s").unwrap();
///
/// let hero_rank = omaha_hi_evaluator::evaluate_hand(&hero_hand, &board).unwrap();
/// let villan_rank = omaha_hi_evaluator::evaluate_hand(&villan_hand, &board).unwrap();
///
/// assert_eq!(hero_rank.description.as_ref().unwrap(), "10 High Straight");
/// assert_eq!(villan_rank.description.as_ref().unwrap(), "Trip Aces");
///
/// assert!(hero_rank > villan_rank); // Hero's hand is better than the villan's
/// ```
/// An evaluator for Omaha Hi-Lo hands
///
/// Similar to the Omaha Hi evaluator, this requires 4 player cards and at least 3 cards from the
/// board in order to evaluate properly. Only 2 cards may be used from the player's hand to fulfill
/// their high hand and lo hand (can be the same pair or different). The lo hand only plays if the
/// player cards has at least 2 cards and the board has at least 3 cards with a distinct rank
/// between A-8. Since the lo hand only applies under a condition, the return value of the evaluator
/// contains Option types to signify the player does not have a lo hand.
///
/// ## Examples
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::omaha_hilo_evaluator};
///
/// let hand = Card::vec_from_str("2cAsAcKc").unwrap();
/// let board = Card::vec_from_str("Ks2sTd8h7d").unwrap();
///
/// let ranks = omaha_hilo_evaluator::evaluate_hand(&hand, &board).unwrap();
///
/// // Notice: Even though we have Aces in our hand, we can only use 2 cards from out hand to
/// // make the best hand (e.g. the K and the 2 pair with the board).
/// assert_eq!(ranks.hi_rank.description.as_ref().unwrap(), "Two Pair of Kings and 2s");
/// // While we have A2 in our hand, the board has 278, which is only 4 distinct ranks, so no
/// // lo rank exists
/// assert_eq!(ranks.lo_rank, None);
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::omaha_hilo_evaluator};
///
/// let hand = Card::vec_from_str("As2d5sAd").unwrap();
/// let board = Card::vec_from_str("Tc5c3s6c8c").unwrap();
///
/// let ranks = omaha_hilo_evaluator::evaluate_hand(&hand, &board).unwrap();
///
/// assert_eq!(ranks.hi_rank.description.as_ref().unwrap(), "Pair of Aces");
/// assert_eq!(ranks.lo_rank.as_ref().unwrap().description.as_ref().unwrap(), "6-5-3-2-A");
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::omaha_hilo_evaluator};
///
/// let hero_hand = Card::vec_from_str("5s6c9s7c").unwrap();
/// let villan_hand = Card::vec_from_str("AhKdAsTh").unwrap();
/// let board = Card::vec_from_str("8hTcAdQs6s").unwrap();
///
/// let hero_ranks = omaha_hilo_evaluator::evaluate_hand(&hero_hand, &board).unwrap();
/// let villan_ranks = omaha_hilo_evaluator::evaluate_hand(&villan_hand, &board).unwrap();
///
/// assert_eq!(hero_ranks.hi_rank.description.as_ref().unwrap(), "10 High Straight");
/// assert_eq!(villan_ranks.hi_rank.description.as_ref().unwrap(), "Trip Aces");
///
/// assert_eq!(hero_ranks.lo_rank.as_ref().unwrap().description.as_ref().unwrap(), "8-7-6-5-A");
/// assert_eq!(villan_ranks.lo_rank, None);
///
/// assert!(hero_ranks.hi_rank > villan_ranks.hi_rank); // Hero's hi hand is better than the villan's
/// assert!(hero_ranks.lo_rank.gt(&villan_ranks.lo_rank)); // Hero's lo hand is better than the villan's
/// ```
/// An evaluator for Dramaha High hands
///
/// Dramaha High is a combination of Five Card Draw and Big O (an Omaha variant). This evaluator
/// makes use of both the HighEvaluator and OmahaHighEvaluator.
///
/// ## Examples
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::dramaha_high_evaluator};
///
/// let hand = Card::vec_from_str("5cAsKdKcAc").unwrap();
/// let board = Card::vec_from_str("Ks6s2d8c3h").unwrap();
///
/// let rank = dramaha_high_evaluator::evaluate_hand(&hand, &board).unwrap();
///
/// assert_eq!(rank.omaha_rank.description.as_ref().unwrap(), "Trip Kings");
/// assert_eq!(rank.draw_rank.description.as_ref().unwrap(), "Two Pair of Aces and Kings");
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::dramaha_high_evaluator};
///
/// let hand = Card::vec_from_str("3s9sAsTsQs").unwrap();
/// let board = Card::vec_from_str("4d9hQdTcKh").unwrap();
///
/// let rank = dramaha_high_evaluator::evaluate_hand(&hand, &board).unwrap();
///
/// assert_eq!(rank.omaha_rank.description.as_ref().unwrap(), "Two Pair of Queens and 10s");
/// assert_eq!(rank.draw_rank.description.as_ref().unwrap(), "Ace High Flush");
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::dramaha_high_evaluator};
///
/// let hero_hand = Card::vec_from_str("Tc9sJs8hQd").unwrap();
/// let villan_hand = Card::vec_from_str("AsQcKdQhAc").unwrap();
/// let board = Card::vec_from_str("8d8s3cAh7d").unwrap();
///
/// let hero_rank = dramaha_high_evaluator::evaluate_hand(&hero_hand, &board).unwrap();
/// let villan_rank = dramaha_high_evaluator::evaluate_hand(&villan_hand, &board).unwrap();
///
/// // Omaha Rank
/// assert_eq!(hero_rank.omaha_rank.description.as_ref().unwrap(), "Trip 8s");
/// assert_eq!(villan_rank.omaha_rank.description.as_ref().unwrap(), "Aces Full of 8s");
///
/// assert!(hero_rank.omaha_rank < villan_rank.omaha_rank); // Villan's hand is better than the hero's
///
/// // 5-card Draw Rank
/// assert_eq!(hero_rank.draw_rank.description.as_ref().unwrap(), "Queen High Straight");
/// assert_eq!(villan_rank.draw_rank.description.as_ref().unwrap(), "Two Pair of Aces and Queens");
///
/// assert!(hero_rank.draw_rank > villan_rank.draw_rank); // Hero's hand is better than the villan's
/// ```
/// An evaluator for Badugi hands
///
/// Badugi is a lowball Poker variant where the goal is get the lowest possible hand. Aces are
/// considered low. Hands can range from 1-4 cards, and all cards within the hand must be distinct
/// in suit and rank. All 4-card hands, Badugis, beat all 3 card hands, all 3-card hands beat all
/// 2-card hands, and all 2-card hands beat all 1-card hands.
///
/// ## Examples
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::badugi_evaluator};
///
/// let hand = Card::vec_from_str("As4d7cTh").unwrap();
///
/// let rank = badugi_evaluator::evaluate_hand(&hand).unwrap();
///
/// assert_eq!(rank.description.as_ref().unwrap(), "10-high Badugi");
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::badugi_evaluator};
///
/// let hand = Card::vec_from_str("QsKs8sJd").unwrap();
///
/// let rank = badugi_evaluator::evaluate_hand(&hand).unwrap();
///
/// assert_eq!(rank.description.as_ref().unwrap(), "Jack-high 2-card hand");
/// ```
///
/// ```rust
/// use playing_cards::{core::Card, poker::evaluators::badugi_evaluator};
///
/// let hero_hand = Card::vec_from_str("Kh3hJcTd").unwrap();
/// let villan_hand = Card::vec_from_str("4d8dTsJh").unwrap();
///
/// let hero_rank = badugi_evaluator::evaluate_hand(&hero_hand).unwrap();
/// let villan_rank = badugi_evaluator::evaluate_hand(&villan_hand).unwrap();
///
/// assert_eq!(hero_rank.description.as_ref().unwrap(), "Jack-high 3-card hand");
/// assert_eq!(villan_rank.description.as_ref().unwrap(), "Jack-high 3-card hand");
///
/// assert!(hero_rank > villan_rank);
/// ```