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, field of view, pathfinding, ranked ordering, and bounded
5//! resources. The goal is to
6//! provide flexible, modular tools to simplify prototyping and building games and simulations.
7//!
8//! ## Features
9//! - `cards`: generic card faces plus deck, hand, and pile abstractions, with standard 52-card and Uno helpers.
10//! - `dice`: `Die` and `Rolls` support for regular and exploding dice along with common roll-analysis helpers.
11//! - `grid`: point-addressed rectangular grids with bounded or toroidal row, column, and neighbor traversal helpers.
12//! - `fov`: field-of-view maps with raycasting, shadowcasting, and rectangle-based algorithms.
13//! - `pathfinding`: Dijkstra maps plus A* variants for bounded or toroidal grids.
14//! - `ordering`: stable ranked lists (`RankedOrder`) and heap-backed queues (`PriorityQueue`) for turn order and scheduling.
15//! - `metered_resource`: bounded unsigned counters with saturating increase and reduction helpers.
16//! - `refilling_pool`: infinitely reusable random pools with conditional and contextual draw helpers.
17//! - `spinners`: decision wheels with weighted, coverable wedges that can hold arbitrary values.
18//! - `dominos`: domino set creation, train management, and longest-train solving.
19//! - Module-specific error enums plus `GameError` / `GameResult` for aggregate error handling across the crate.
20
21pub mod cards;
22pub use cards::{
23 AddCard, Card, CardCollection, CardFaces, CardHand, Deck, Hand, Pile, Rank, Suit, TakeCard,
24};
25
26pub mod dice;
27pub use dice::{Die, DieResult, Rolls};
28
29pub mod dominos;
30pub use dominos::{BonePile, Domino, DominoHand, MAX_PIPS, Train};
31
32pub mod metered_resource;
33pub use metered_resource::MeteredResource;
34
35pub mod refilling_pool;
36pub use refilling_pool::RefillingPool;
37
38pub mod spinners;
39pub use spinners::{Spinner, Wedge, wedges_from_tuples, wedges_from_values};
40
41pub mod gameerror;
42pub use gameerror::{
43 CardError, DiceError, DominoError, GameError, GridError, PathfindingError, RefillingPoolError,
44 SpinnerError, ValueError,
45};
46
47pub mod grid;
48pub use grid::{Grid, GridSize, GridTopology, Point, PointDelta};
49
50pub mod fov;
51pub use fov::{
52 BlockingRect, FovMap, RectangleFov, perimeter_raycasting, perimeter_raycasting_into,
53 rectangle_based_fov, rectangle_based_fov_into, recursive_shadowcasting,
54 recursive_shadowcasting_into,
55};
56
57pub mod ordering;
58pub use ordering::{
59 AscendingOrder, DescendingOrder, Max, MaxPriorityQ, Min, MinPriorityQ, PriorityQueue,
60 RankedOrder,
61};
62
63pub mod pathfinding;
64pub use pathfinding::{
65 Cost, HeuristicWeight, MoveSet, Path, SearchMap, a_star, a_star_weighted,
66 a_star_weighted_with_topology, a_star_with_topology, dijkstra_map, dijkstra_map_with_topology,
67 path_from_search_map,
68};
69
70/// The crate-wide result type for APIs that can return [`GameError`].
71pub type GameResult<T> = Result<T, GameError>;
72
73/// Returns early with the supplied error when a condition is false.
74///
75/// The error is converted into the enclosing function's error type with [`Into`].
76#[macro_export]
77macro_rules! ensure {
78 ($cond:expr, $err:expr) => {
79 if !$cond {
80 return Err($err.into());
81 }
82 };
83}