gametools
gametools is a lightweight Rust library implementing components and mechanics common to tabletop and many other games. It's intended to be reusable and simplify the creation of games and game engines without blurring into the realm of physical simulation of apparatus or game-specific logic.
Features
dice:DieandRollssupport plain and exploding dice plus common roll analysis helpers likehistogram,highest,lowest, andcount_where.cards: extensible card/deck/hand/pile toolkit for custom face types, plus ready-made standard 52-card and Uno helpers.dominos: domino set creation, trains, hands, and longest-train solving.spinners: weighted wedges with optional covering/blocking and chainable updates.refilling_pool: a randomized pool of any clonable type that refills itself when empty, with conditional and contextual draw helpers.ordering:RankedOrderandPriorityQueuefor stable ranked lists or heap-backed priority scheduling, with min/max or ascending/descending aliases.- Unit tests, doctests, and runnable examples across the crate.
Example: Cards
use ;
;
let runes = "FUTHARK".chars
.map
.;
let mut deck = new;
deck.shuffle;
let mut hand = new;
hand.add_cards;
assert_eq!;
Example: Dice
use Die;
let rolls = new.expect.roll_n;
let histogram = rolls.histogram;
if histogram.len == 2 && histogram.values.any
if histogram.len == 1
Example: Spinners
use ;
let wedges = wedges_from_values;
let spinner = new;
if let Some = spinner.spin
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
- Dice module: regular and exploding dice plus
Rollshelpers - Dominos module: longest-train solver
- Ordering module: ranked lists and priority queues
- RefillingPool module: self-refilling random pools with contextual draws
- Spinners module: weighted wedges with optional blocking
cargo run --example cards: ties the standard playing cards and Uno helpers together for a mini showdowncargo run --example dice: basic roll analysis, exploding dice, and poker-style histogram checkscargo run --example refilling_pool: an "infinite chest" that prefers loot based on character contextcargo run --example priority_queue: ship attack ordering withMinPriorityQcargo run --example ranked_order: initiative ordering withDescendingOrder
License
Licensed under MIT. Contributions welcome!