Struct cardpack::cards::pile::Pile

source ·
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

source

pub fn from_vector(v: Vec<Card>) -> Self

source

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.

source

pub fn pile_up<F>(x: usize, f: F) -> Self
where 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.

source

pub fn push(&mut self, elem: Card)

Places the Card at the bottom (end) of the Pile.

source

pub fn append(&mut self, other: &Pile)

Appends a clone of the passed in Pile of Cards to the existing Pile.

source

pub fn insert(&mut self, index: usize, elem: Card)

Places the card at the given index

source

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.

source

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/

source

pub fn to_index_locale(&self, lid: &LanguageIdentifier) -> String

source

pub fn to_symbol_index(&self) -> String

source

pub fn to_symbol_index_locale(&self, lid: &LanguageIdentifier) -> String

source

pub fn card_by_index(&self, index: &str) -> Option<&Card>

source

pub fn cards(&self) -> &Vec<Card>

Returns a reference to the Vector containing all the cards.

source

pub fn cards_by_suit(&self, suit: Suit) -> Vec<Card>

Returns a Vector of Cards matching the passed in Suit.

source

pub fn contains(&self, card: &Card) -> bool

Tests if a card is in the Pile.

source

pub fn contains_all(&self, pile: &Pile) -> bool

Tests if every element is inside the Pile.

source

pub fn demo(&self)

This function is designed to demonstrate the capabilities of the library.

source

pub fn demo_short(&self)

source

pub fn draw(&mut self, x: usize) -> Option<Pile>

source

pub fn draw_first(&mut self) -> Option<Card>

source

pub fn draw_last(&mut self) -> Option<Card>

source

pub fn first(&self) -> Option<&Card>

source

pub fn get(&self, index: usize) -> Option<&Card>

source

pub fn get_random(&self) -> Option<&Card>

source

pub fn is_empty(&self) -> bool

source

pub fn last(&self) -> Option<&Card>

source

pub fn len(&self) -> usize

source

pub fn map_by_rank_count(&self) -> HashMap<Rank, usize>

source

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

source

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.

source

pub fn position(&self, karte: &Card) -> Option<usize>

source

pub fn pile_by_index(&self, indexes: &[&str]) -> Option<Pile>

source

pub fn prepend(&mut self, other: &Pile)

source

pub fn ranks(&self) -> Vec<Rank>

source

pub fn rank_indexes(&self) -> String

Returns a String of all of the Rank Index Characters for a Pile.

source

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

source

pub fn remove(&mut self, index: usize) -> Card

source

pub fn remove_card(&mut self, card: &Card) -> Option<Card>

source

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.

source

pub fn short_index_for_suit(&self, suit: Suit) -> String

source

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.

source

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.

source

pub fn shuffle(&self) -> Pile

Returns a new, sorted Pile. Sorting is determined by the weight set for each Card in the Pile.

source

pub fn shuffle_in_place(&mut self)

source

pub fn sort(&self) -> Pile

source

pub fn sort_in_place(&mut self)

source

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.

source

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.

source

pub fn suits(&self) -> Vec<Suit>

Returns a sorted collection of the unique Suits in a Pile.

source

pub fn values(&self) -> impl Iterator<Item = &Card>

source

pub fn jokers() -> Pile

source

pub fn canasta_base_single_deck() -> Pile

source

pub fn canasta_single_deck() -> Pile

source

pub fn euchre_deck() -> Pile

source

pub fn french_deck() -> Pile

source

pub fn french_deck_with_jokers() -> Pile

source

pub fn pinochle_deck() -> Pile

source

pub fn short_deck() -> Pile

source

pub fn skat_deck() -> Pile

source

pub fn spades_deck() -> Pile

source

pub fn tarot_deck() -> Pile

source

pub fn sig_generate_from_strings(strings: &[String]) -> String

Trait Implementations§

source§

impl Clone for Pile

source§

fn clone(&self) -> Pile

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Pile

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Pile

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for Pile

Sets the to_string() function for a Pile to return the default index signature for the Pile.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromIterator<Card> for Pile

source§

fn from_iter<T: IntoIterator<Item = Card>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl Hash for Pile

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl IntoIterator for Pile

§

type Item = Card

The type of the elements being iterated over.
§

type IntoIter = IntoIter<<Pile as IntoIterator>::Item>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq for Pile

source§

fn eq(&self, other: &Pile) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Pile

Auto Trait Implementations§

§

impl Freeze for Pile

§

impl RefUnwindSafe for Pile

§

impl Send for Pile

§

impl Sync for Pile

§

impl Unpin for Pile

§

impl UnwindSafe for Pile

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AnyEq for T
where T: Any + PartialEq,

source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V