Crate spades

Source
Expand description

This crate provides an implementation of the four person card game, spades.

§Example usage

extern crate rand;
extern crate uuid;
extern crate spades;
 
use std::{io};
use spades::{Game, GameTransition, State};
use rand::{thread_rng, Rng};
 
let mut g = Game::new(uuid::Uuid::new_v4(), 
   [uuid::Uuid::new_v4(), 
    uuid::Uuid::new_v4(), 
    uuid::Uuid::new_v4(), 
    uuid::Uuid::new_v4()], 
    500);
 
 
g.play(GameTransition::Start);
 
while *g.get_state() != State::Completed {
    let mut stdin = io::stdin();
    let input = &mut String::new();
    let mut rng = thread_rng();
    if let State::Trick(_playerindex) = *g.get_state() {
        assert!(g.get_current_hand().is_ok());
        let hand = g.get_current_hand().ok().unwrap().clone();
 
        let random_card = rng.choose(hand.as_slice()).unwrap();
         
        g.play(GameTransition::Card(random_card.clone()));
    } else {
        g.play(GameTransition::Bet(3));
    }
}
assert_eq!(*g.get_state(), State::Completed);

Structs§

Card
Intuitive card struct. Comparisons are made according to alphabetical order, ascending.
Game
Primary game state. Internally manages player rotation, scoring, and cards.

Enums§

GameTransition
The primary way to interface with a spades game. Used as an argument to Game::play.
GetError
Rank
State
Current game stage, field of Game.
Suit
TransitionError
TransitionSuccess

Functions§

deal_four_players
Used to reshuffle a deck of cards, panics if the cards does not have 52 elements (should only be used on a “full” deck).
get_trick_winner
Given four cards and a starting card, returns the winner of a trick.
new_deck
Returns a shuffled deck of deck::Card’s, with 52 elements.
new_pot
Returns an array of Blank suited and ranked cards.
shuffle
Shuffles a Vector of cards in place, see rand::thread_rng::shuffle.