card: move all_same_rank and add documentation

This commit is contained in:
2026-04-02 04:17:51 +01:00
committed by oreodave
parent ca07536b37
commit 04cf388f59

View File

@@ -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<Card> { pub fn make_decks(number_of_decks: usize) -> Vec<Card> {
let number_of_decks: i64 = number_of_decks.try_into().unwrap(); let number_of_decks: i64 = number_of_decks.try_into().unwrap();
(-(number_of_decks * 2)..(52 * number_of_decks)) (-(number_of_decks * 2)..(52 * number_of_decks))