Rust implementation of the four-player trick-taking card game Spades. Rules: pagat.com/auctionwhist/spades.html.
[dependencies]
spades = "1.1"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, // optional TimerConfig
);
g.play(GameTransition::Start);
while *g.get_state() != State::Completed {
let mut rng = thread_rng();
if let State::Trick(_) = *g.get_state() {
let hand = g.get_current_hand().unwrap().clone();
let card = hand.as_slice().choose(&mut rng).unwrap();
g.play(GameTransition::Card(card.clone()));
} else {
g.play(GameTransition::Bet(3));
}
}Optional HTTP server for hosting concurrent multiplayer games. Includes matchmaking, challenge links, WebSocket game subscriptions, SSE event streams, optional SQLite persistence, and Fischer increment timers.
cargo run --features server -- --port 3000
cargo run --features server -- --port 3000 --db games.sqliteSee SERVER.md for the full API reference.
Nil bids are supported (bet zero for +/-100 point bonus/penalty). Blind bids are not yet supported.
Issues and pull requests welcome.