Struct Deck

Source
pub struct Deck { /* private fields */ }

Implementations§

Source§

impl Deck

Source

pub fn new() -> Deck

Returns a shuffled Deck.

Source

pub fn simplify(&mut self)

Removes all cards from the deck that do not have a solid shading. This is useful as a deck for beginners.

Source

pub fn is_empty(&self) -> bool

Source

pub fn remainder(&self) -> usize

Source

pub fn draw(&mut self, n: usize) -> Vec<Card>

Source§

impl Deck

Source

pub fn draw_guaranteeing_set(&mut self, hand: &[Card]) -> Option<Vec<Card>>

The smallest number of cards guaranteed to contain a Set is 21. However, the odds that there are no sets in 18 cards is so low that it almost never happens in practice. As long as there are at least 6 cards in the stock, we can doctor the deck to guarantee that 18 cards will contain a Set:

15 (table) + 6 (stock) == 21

If there are only 3 more cards to deal, you could still get stuck with 18 cards, but at that point the game would be over.

In the worst case scenario, 15 cards are on the table, 6 remain in the stock, and there’s exactly 1 Set amongst those 21 cards.* There are 3 cases we need to handle:

  1. Two cards from the Set are on the table, and one is in the stock. We need to make sure that the one card in the stock is in the next draw.

  2. One card from the Set is on the table, and two are in the stock. We need to make sure that both cards in the stock are in the next draw.

  3. All three cards in the Set are in the stock. We need to put those three cards into the next draw.

*NOTE: It’s possible that 21 cards always contain 2 or more sets. As far as I know, that’s an open question.

Trait Implementations§

Source§

impl Clone for Deck

Source§

fn clone(&self) -> Deck

Returns a duplicate 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 Default for Deck

Source§

fn default() -> Deck

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

Auto Trait Implementations§

§

impl Freeze for Deck

§

impl RefUnwindSafe for Deck

§

impl Send for Deck

§

impl Sync for Deck

§

impl Unpin for Deck

§

impl UnwindSafe for Deck

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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