[][src]Struct freecell::Foundations

pub struct Foundations(pub [Foundation; 4]);

Four stacks of cards, where each stack contains only cards of one suit, going from Ace upwards.

Rules

There exists one foundation for each of the four suits. Cards can only be put on the foundation corresponding to their suit.

An Ace can be put on the foundation of the appropriate suit iff there is no other card on that foundation. This is always the case in a valid game state.

Any other card c can be put on the foundation of the appropriate suit iff the top card on that foundation has a rank exactly one lower than card c.

This means a foundation can hold at most 13 cards: The cards from Ace to King of one suit in order of their ranks, the Ace being on the bottom and the King being on top. The game ends in a victory when all four foundations reach this state.

Once a card is on a foundation, it can never be removed.

Usage

The position of the Foundation in the array determines which suit it holds. Eg. foundations[1] may only hold spade cards, since Suit::Spade equals 1. TODO [high priority] explain more thoroughly

Examples

// TODO [high priority]

Methods

impl Foundations[src]

pub fn new() -> Foundations[src]

Creates empty foundations

pub fn foundation(&self, suit: Suit) -> &Foundation[src]

Returns the foundation of the given suit

Trait Implementations

impl CardCollection for Foundations[src]

fn add_card(&self, card: Card) -> Result<Self, ()>[src]

Attempts to put a card on the foundation of the appropriate suit.

An Ace can be put on a foundation iff there is no other card on the foundation of that suit. This is always the case in a valid game state.

Any other card c can be put on a foundation iff the top card on the foundation of that suit has a rank exactly one lower than card c.

fn pop_card(&self) -> Vec<(Self, Card)>[src]

Always returns an empty Vec, since cards cannot be removed from foundations.

impl Clone for Foundations[src]

impl Default for Foundations[src]

impl Eq for Foundations[src]

impl PartialEq<Foundations> for Foundations[src]

impl Display for Foundations[src]

impl Debug for Foundations[src]

impl Hash for Foundations[src]

impl StructuralPartialEq for Foundations[src]

impl StructuralEq for Foundations[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]