diff --git a/src/card.rs b/src/card.rs index 8b0d485..e0275ea 100644 --- a/src/card.rs +++ b/src/card.rs @@ -216,9 +216,7 @@ Any sequence of five consecutive cards all of the same suit. For instance, a han 6. Straight Five cards in a sequence, but not all of the same suit. An example would be a hand containing a 2, 3, 4, 5, and 6, of various suits. -7. Three of a Kind (Trips or Set) -Three cards of the same rank and two unrelated cards. An example would be three Queens and two unrelated cards. 8. Two Pair Two different pairs of cards and one unrelated card. For example, a hand with two 10s, two 9s, and an unrelated card would be "two pair." diff --git a/src/match_evaluator.rs b/src/match_evaluator.rs index edff789..bc0542d 100644 --- a/src/match_evaluator.rs +++ b/src/match_evaluator.rs @@ -21,6 +21,9 @@ pub enum Rank { /// Any five cards of the same suit, but not in sequence. For instance, if a player has five heart cards, they have a flush. Flush, Straight, + /// 7. Three of a Kind (Trips or Set) + /// + /// Three cards of the same rank and two unrelated cards. An example would be three Queens and two unrelated cards. ThreeOfAKind, TwoPair, OnePair, @@ -42,7 +45,7 @@ impl MatchHandEvaluator { /// It evaluates the [Rank] of a [Hand] /// pub fn match_eval(hand: &mut Hand) -> Rank { - // first let's sort the hand, that's the reason we need a mutable reference + // first let's sort the hand, that's the reason we need here a mutable reference hand.sort(); println!("Sorted: {}", hand); @@ -71,6 +74,11 @@ impl MatchHandEvaluator { { Rank::Flush } + [Card { val : v1, .. }, Card { val: v2, .. }, Card { val: v3, .. }, Card { val: v4, .. }, Card { val: v5, .. }] + if (v1 == v2 && v2 == v3 || v3 == v4 && v4 == v5) => + { + Rank::ThreeOfAKind + } hand => Rank::HighCard(hand[0]), } @@ -117,4 +125,10 @@ mod test { assert_rank!(hand!["Kd", "Kh", "Kc", "8s", "8d"], Rank::FullHouse); assert_rank!(hand!["2d", "2h", "Qc", "Qs", "Qd"], Rank::FullHouse); } + + #[test] + fn rank_3_of_a_kind() { + assert_rank!(hand!["Kd", "Kh", "Kc", "10s", "8d"], Rank::ThreeOfAKind); + assert_rank!(hand!["2d", "Jh", "Qc", "Qs", "Qd"], Rank::ThreeOfAKind); + } }