pub struct Pile(/* private fields */);
Expand description
A Pile is a sortable collection of Cards.
§Usage:
let mut pile = cardpack::Pile::default();
let ace_of_spades = cardpack::Card::from_index_strings(cardpack::ACE, cardpack::SPADES);
let ace_of_hearts = cardpack::Card::from_index_strings(cardpack::ACE, cardpack::HEARTS);
pile.push(ace_of_spades);
pile.push(ace_of_hearts);
pile.shuffle();
Implementations§
source§impl Pile
impl Pile
pub fn from_vector(v: Vec<Card>) -> Self
sourcepub fn pile_on(piles: Vec<Pile>) -> Self
pub fn pile_on(piles: Vec<Pile>) -> Self
Takes a reference to an Array of Piles and consolidates them into a single Pile of Cards.
sourcepub fn pile_up<F>(x: usize, f: F) -> Selfwhere
F: Fn() -> Self,
pub fn pile_up<F>(x: usize, f: F) -> Selfwhere
F: Fn() -> Self,
Allows you to pass in an integer and a Pile returning function method and creates a Pile made up of the Piles generated that many times.
§Usage:
let pile = cardpack::Pile::pile_up(6, cardpack::Pile::french_deck);
pile.shuffle();
This creates and shuffles a Pile made up of six traditional French decks, which would be suitable for a casino blackjack table.
sourcepub fn append(&mut self, other: &Pile)
pub fn append(&mut self, other: &Pile)
Appends a clone of the passed in Pile of Cards to the existing Pile.
sourcepub fn to_index(&self) -> String
pub fn to_index(&self) -> String
Returns a simple string representation of the Cards in the Pile based upon the
default language local, which is US_ENGLISH
.
sourcepub fn to_index_str(&self) -> &'static str
pub fn to_index_str(&self) -> &'static str
Returns a static str of the Pack’s index. Mainly used for testing deserialization.
Idea from: https://stackoverflow.com/a/52367953/
pub fn to_index_locale(&self, lid: &LanguageIdentifier) -> String
pub fn to_symbol_index(&self) -> String
pub fn to_symbol_index_locale(&self, lid: &LanguageIdentifier) -> String
pub fn card_by_index(&self, index: &str) -> Option<&Card>
sourcepub fn cards_by_suit(&self, suit: Suit) -> Vec<Card>
pub fn cards_by_suit(&self, suit: Suit) -> Vec<Card>
Returns a Vector of Cards matching the passed in Suit.
sourcepub fn contains_all(&self, pile: &Pile) -> bool
pub fn contains_all(&self, pile: &Pile) -> bool
Tests if every element is inside the Pile.
pub fn demo_short(&self)
pub fn draw(&mut self, x: usize) -> Option<Pile>
pub fn draw_first(&mut self) -> Option<Card>
pub fn draw_last(&mut self) -> Option<Card>
pub fn first(&self) -> Option<&Card>
pub fn get(&self, index: usize) -> Option<&Card>
pub fn get_random(&self) -> Option<&Card>
pub fn is_empty(&self) -> bool
pub fn last(&self) -> Option<&Card>
pub fn len(&self) -> usize
pub fn map_by_rank_count(&self) -> HashMap<Rank, usize>
sourcepub fn map_by_rank(&self) -> HashMap<Rank, Pile>
pub fn map_by_rank(&self) -> HashMap<Rank, Pile>
Takes a Pile
and returns a HashMap
with the key as each Suit
in the Pile
with the values
as a Pile
of the cards for that Suit.
TODO: Make generic
sourcepub fn map_by_suit(&self) -> HashMap<Suit, Pile>
pub fn map_by_suit(&self) -> HashMap<Suit, Pile>
Takes a Pile
and returns a HashMap
with the key as each Suit
in the Pile
with the values
as a Pile
of the cards for that Suit.
pub fn position(&self, karte: &Card) -> Option<usize>
pub fn pile_by_index(&self, indexes: &[&str]) -> Option<Pile>
pub fn prepend(&mut self, other: &Pile)
pub fn ranks(&self) -> Vec<Rank>
sourcepub fn rank_indexes(&self) -> String
pub fn rank_indexes(&self) -> String
Returns a String of all of the Rank Index Characters for a Pile.
sourcepub fn rank_indexes_with_separator(&self, separator: &'static str) -> String
pub fn rank_indexes_with_separator(&self, separator: &'static str) -> String
Returns a String of all of the Rank Index Characters for a Pile.
TODO: There has to be an easier way to do this :-P
pub fn remove(&mut self, index: usize) -> Card
pub fn remove_card(&mut self, card: &Card) -> Option<Card>
sourcepub fn shift_rank_weight_left(&self, i: usize) -> Pile
pub fn shift_rank_weight_left(&self, i: usize) -> Pile
Returns a Pile
with a geometric binary shift operation performed on the
existing one. Used for frequency sorting on a Pile
of Cards
.
pub fn short_index_for_suit(&self, suit: Suit) -> String
sourcepub fn short_suit_indexes(&self) -> Vec<String>
pub fn short_suit_indexes(&self) -> Vec<String>
Returns a Vector of index strings, one for each Suit
in the Pile
, that starts with
the Card's
Suit
symbol followed by the Rank
for each Card
in the Pile
.
This is useful for creating displays such as the ones in Bridge columns.
sourcepub fn short_suit_indexes_to_string(&self) -> String
pub fn short_suit_indexes_to_string(&self) -> String
Returns a String where each line is the short suit index for the Pile. This format is common to display hands in Bridge.
sourcepub fn shuffle(&self) -> Pile
pub fn shuffle(&self) -> Pile
Returns a new, sorted Pile
. Sorting is determined by the weight set for
each Card
in the Pile
.
pub fn shuffle_in_place(&mut self)
pub fn sort(&self) -> Pile
pub fn sort_in_place(&mut self)
sourcepub fn sort_by_frequency(&self) -> Pile
pub fn sort_by_frequency(&self) -> Pile
Takes the existing Pile
and returns a new one with a sort emphasizing
the frequency of the cards passed in. The more Cards
of a specific
Rank
, the higher the weight each Card
is given.
sourcepub fn convert_to_rank_weighted(&self) -> Pile
pub fn convert_to_rank_weighted(&self) -> Pile
Takes the entire Pile and returns a new Pile where the cards in it are Rank weighted first instead of Suit weighted first. Useful for when displays need to sort by Rank.
use cardpack::{Card, CLUBS, HEARTS, JACK, QUEEN, Pile};
let qh = Card::from_index_strings(QUEEN, HEARTS);
let jh = Card::from_index_strings(JACK, HEARTS);
let qc = Card::from_index_strings(QUEEN, CLUBS);
let jc = Card::from_index_strings(JACK, CLUBS);
let pile = Pile::from_vector(vec![qh, jh, jc, qc]);
let rank_weighted = pile.convert_to_rank_weighted();
println!("{}", rank_weighted.sort());
This will print out QH QC JH JC
.
pub fn values(&self) -> impl Iterator<Item = &Card>
pub fn jokers() -> Pile
pub fn canasta_base_single_deck() -> Pile
pub fn canasta_single_deck() -> Pile
pub fn euchre_deck() -> Pile
pub fn french_deck() -> Pile
pub fn french_deck_with_jokers() -> Pile
pub fn pinochle_deck() -> Pile
pub fn short_deck() -> Pile
pub fn skat_deck() -> Pile
pub fn spades_deck() -> Pile
pub fn tarot_deck() -> Pile
pub fn sig_generate_from_strings(strings: &[String]) -> String
Trait Implementations§
source§impl Display for Pile
impl Display for Pile
Sets the to_string()
function for a Pile
to return the default index signature for the Pile
.