| Crates.io | gametools |
| lib.rs | gametools |
| version | 0.7.0 |
| created_at | 2025-04-06 06:51:06.911555+00 |
| updated_at | 2025-11-15 02:37:16.441566+00 |
| description | Game component toolkit for dice, dominos, spinners, and fully extensible card decks. |
| homepage | |
| repository | https://github.com/pygmy-twylyte/gametools |
| max_upload_size | |
| id | 1622677 |
| size | 206,374 |
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.
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);
use gametools::{Die, DicePool};
let d6 = Die::new(6);
let total = d6.roll_into_pool(5)
.take_highest(4)
.nerf(1)
.sum();
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}");
}
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.
Full API docs with usage examples are available via docs.rs.
See additional usage examples in the module docs:
examples/cards: a mashup that ties the standard playing cards and Uno modules together for a mini showdownThe examples/yahtzee folder contains an example of a Yahtzee-playing agent created using the Dice module.
Licensed under MIT. Contributions welcome!