From 04cf388f591519cf51bc9f03f072d2b2f1910125 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Thu, 2 Apr 2026 04:17:51 +0100 Subject: [PATCH] card: move all_same_rank and add documentation --- src/card.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/card.rs b/src/card.rs index 3d99095..690c831 100644 --- a/src/card.rs +++ b/src/card.rs @@ -86,6 +86,17 @@ impl Card { } } +/** Given a sequence of Playing Cards, check if they are all of the same rank. + */ +pub fn all_same_rank(cards: &[PlayingCard]) -> bool { + let rank = cards[0].rank; + cards[1..].iter().all(|card| rank == card.rank) +} + +/** Generate a vector of cards representing the concatenation of + * `number_of_decks` decks of playing cards put together. Note that each deck + * gets two jokers - this is added to the overall vector. + */ pub fn make_decks(number_of_decks: usize) -> Vec { let number_of_decks: i64 = number_of_decks.try_into().unwrap(); (-(number_of_decks * 2)..(52 * number_of_decks))