Expand description
This crate provides an implementation of the four person card game, spades.
§Example usage
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(); 4],
100,
None,
);
g.play(GameTransition::Start).unwrap();
let mut rng = thread_rng();
while *g.get_state() != State::Completed {
if let State::Trick(_) = *g.get_state() {
let legal = g.get_legal_cards().unwrap();
let card = *legal.choose(&mut rng).unwrap();
g.play(GameTransition::Card(card)).unwrap();
} else {
g.play(GameTransition::Bet(3)).unwrap();
}
}
assert_eq!(*g.get_state(), State::Completed);Modules§
- ai
- transcript
- Spades Transcript Format (STF) — PGN-inspired serialization of full game history.
Structs§
- Card
- Intuitive card struct. Comparisons are made according to alphabetical order, ascending.
- Game
- Primary game state. Internally manages player rotation, scoring, and cards.
- Player
Clocks - Remaining clock time for each player in milliseconds.
- Timer
Config - Fischer increment timer configuration (X+Y: X minutes initial, Y seconds increment per move).
Enums§
- Game
Transition - 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
- Transition
Error - Transition
Success
Functions§
- deal_
four_ players - Deals a 52-card deck out to four hands. Panics if
cardsdoes not have 52 elements. Caller is responsible for shuffling first. - 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. - short_
id_ to_ uuid - shuffle
- Shuffles a slice of cards in place, see
rand::seq::SliceRandom::shuffle. - uuid_
to_ short_ id