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§

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

Enums§

Functions§