9 releases (5 breaking)
Uses new Rust 2024
| new 0.6.0 | Nov 8, 2025 |
|---|---|
| 0.5.0 | Nov 3, 2025 |
| 0.4.0 | Jul 19, 2025 |
| 0.3.2 | May 15, 2025 |
| 0.1.1 | Apr 10, 2025 |
#276 in Game dev
35 downloads per month
155KB
3K
SLoC
gametools
gametools is a lightweight Rust library for simulating game components like dice rolls, extensible card decks, dominos, and spinners. It's designed to be modular, testable, and usable in both game engines and CLI tools. The goal is to provide reusable game apparatus — not game logic — so you can build your rules on top of well-tested building blocks.
Features
- 🎲 Numeric dice up to 255 sides, plus dice pools with chainable operations
- 🃏 Extensible cards toolkit: compose custom face types, deck/hand/pile flows, plus ready-made standard 52-card and Uno helpers
- 🁫 Dominos with support for longest-path train solving
- 🌀 Spinners with support for weighted wedges and optional blocking
- 💥 Human-readable game errors for common failure conditions
- 🧪 Well-documented and tested with 90%+ code coverage
Example: Cards
use gametools::{AddCard, Card, CardCollection, CardFaces, Deck, Hand, TakeCard};
#[derive(Clone)]
struct Rune(char);
impl CardFaces for Rune {
fn display_front(&self) -> String { format!("Rune {}", self.0) }
fn display_back(&self) -> Option<String> { Some(String::from("Stone Tablet")) }
fn matches(&self, other: &Self) -> bool { self.0 == other.0 }
fn compare(&self, other: &Self) -> std::cmp::Ordering { self.0.cmp(&other.0) }
}
let runes = "FUTHARK".chars()
.map(|glyph| Card::new_card(Rune(glyph)))
.collect::<Vec<_>>();
let mut deck = Deck::new("runes", runes);
deck.shuffle();
let mut hand = Hand::<Rune>::new("sage");
hand.add_cards(deck.take_cards(3));
assert_eq!(hand.size(), 3);
Example: Dice
use gametools::{Die, DicePool};
let d6 = Die::new(6);
let total = d6.roll_into_pool(5)
.take_highest(4)
.nerf(1)
.sum();
Example: Spinners
use gametools::spinners::{Spinner, wedges_from_values};
let wedges = wedges_from_values(vec!["Rock", "Paper", "Scissors"]);
let spinner = Spinner::new(wedges);
if let Some(result) = spinner.spin() {
println!("You chose: {result}");
}
The Idea
This crate avoids hardcoding game rules. Instead, it provides flexible, composable abstractions to make building games easier — whether you're making a tabletop simulator, card game engine, or randomizer tool.
Documentation
Full API docs with usage examples are available via docs.rs.
More Examples
See additional usage examples in the module docs:
- Cards module: custom faces, deck/hand/pile traits, shuffling, drawing
- Dominos module: longest-train solver
examples/cards: a mashup that ties the standard playing cards and Uno modules together for a mini showdown
The examples/yahtzee folder contains an example of a Yahtzee-playing agent created using the Dice module.
License
Licensed under MIT. Contributions welcome!
Dependencies
~1–1.7MB
~33K SLoC