/// 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*.
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*.
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 add_card(&self, card: Card) -> Result<Self, ()> {
        // check whether the card can be put on any foundation
        if self.foundation(card.suit).is_empty() {
            // only Aces can be put on an empty foundation
            if card.rank != ACE {
                return Err(());
            }
        } else if
            // Aces can only be put on an empty foundation
            card.rank == ACE ||
            // Other cards can only be put on a foundation if it is one rank higher than the
            // currently topmost card on the foundation
            self.foundation(card.suit).last().unwrap().rank + 1 != card.rank
        {
            return Err(());
        }
        let mut clone = self.clone();
        clone.0[card.suit as usize].push(card);
        Ok(clone)
    }
fn add_card ( & self , card : Card ) -> Result < Self , ( ) > { // check whether the card can be put on any foundation if self . foundation ( card . suit ) . is_empty ( ) { // only Aces can be put on an empty foundation if card . rank != ACE { return Err ( ( ) ) ; } } else if // Aces can only be put on an empty foundation card . rank == ACE || // Other cards can only be put on a foundation if it is one rank higher than the // currently topmost card on the foundation self . foundation ( card . suit ) . last ( ) . unwrap ( ) . rank + 1 != card . rank { return Err ( ( ) ) ; } let mut clone = self . clone ( ) ; clone . 0 [ card . suit as usize ] . push ( card ) ; Ok ( clone ) }
Attempts to put a card on the foundation of the appropriate suit.
Attempts to put a card on the foundation of the appropriate suit .
&self
card
Card