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 ;
;
let runes = "FUTHARK".chars
.map
.;
let mut deck = new;
deck.shuffle;
let mut hand = new;
hand.add_cards;
assert_eq!;
Example: Dice
use ;
let d6 = new;
let total = d6.roll_into_pool
.take_highest
.nerf
.sum;
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
- 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!