Skip to main content

Crate spades

Crate spades 

Source
Expand description

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

§Example usage

use std::{io};
use spades::{Game, GameTransition, State};
use rand::seq::SliceRandom;
use rand::thread_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, None);
 
 
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 = hand.as_slice().choose(&mut rng).unwrap();
         
        g.play(GameTransition::Card(random_card.clone()));
    } else {
        g.play(GameTransition::Bet(3));
    }
}
assert_eq!(*g.get_state(), State::Completed);

Modules§

ai

Structs§

Card
Intuitive card struct. Comparisons are made according to alphabetical order, ascending.
Game
Primary game state. Internally manages player rotation, scoring, and cards.
PlayerClocks
Remaining clock time for each player in milliseconds.
TimerConfig
Fischer increment timer configuration (X+Y: X minutes initial, Y seconds increment per move).

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).
decode_player_url
encode_player_url
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.
short_id_to_uuid
shuffle
Shuffles a Vector of cards in place, see rand::seq::SliceRandom::shuffle.
uuid_to_short_id