Skip to main content

gametools/
lib.rs

1//! # gametools
2//!
3//! `gametools` provides reusable utilities for common game-building needs such as card decks,
4//! dice, spinners, dominos, grids, ranked ordering, and bounded resources. The goal is to
5//! provide flexible, modular tools to simplify prototyping and building games and simulations.
6//!
7//! ## Features
8//! - `cards`: generic card faces plus deck, hand, and pile abstractions, with standard 52-card and Uno helpers.
9//! - `dice`: `Die` and `Rolls` support for regular and exploding dice along with common roll-analysis helpers.
10//! - `grid`: point-addressed rectangular grids with row, column, and neighbor traversal helpers.
11//! - `ordering`: stable ranked lists (`RankedOrder`) and heap-backed queues (`PriorityQueue`) for turn order and scheduling.
12//! - `metered_resource`: bounded unsigned counters with saturating increase and reduction helpers.
13//! - `refilling_pool`: infinitely reusable random pools with conditional and contextual draw helpers.
14//! - `spinners`: decision wheels with weighted, coverable wedges that can hold arbitrary values.
15//! - `dominos`: domino set creation, train management, and longest-train solving.
16//! - Module-specific error enums plus `GameError` / `GameResult` for aggregate error handling across the crate.
17
18pub mod cards;
19pub use cards::{
20    AddCard, Card, CardCollection, CardFaces, CardHand, Deck, Hand, Pile, Rank, Suit, TakeCard,
21};
22
23pub mod dice;
24pub use dice::{Die, DieResult, Rolls};
25
26pub mod dominos;
27pub use dominos::{BonePile, Domino, DominoHand, MAX_PIPS, Train};
28
29pub mod metered_resource;
30pub use metered_resource::MeteredResource;
31
32pub mod refilling_pool;
33pub use refilling_pool::RefillingPool;
34
35pub mod spinners;
36pub use spinners::{Spinner, Wedge, wedges_from_tuples, wedges_from_values};
37
38pub mod gameerror;
39pub use gameerror::{
40    CardError, DiceError, DominoError, GameError, GridError, RefillingPoolError, SpinnerError,
41    ValueError,
42};
43
44pub mod grid;
45pub use grid::{Grid, GridSize, Point, PointDelta};
46
47pub mod ordering;
48pub use ordering::{
49    AscendingOrder, DescendingOrder, Max, MaxPriorityQ, Min, MinPriorityQ, PriorityQueue,
50    RankedOrder,
51};
52pub type GameResult<T> = Result<T, GameError>;
53
54#[macro_export]
55macro_rules! ensure {
56    ($cond:expr, $err:expr) => {
57        if !$cond {
58            return Err($err.into());
59        }
60    };
61}