NoctisRoll
A modern, modular TRPG dice rolling system implementing the OneDice standard.
Features
- Full OneDice support: Implements all dice types from the OneDice specification
- Modular design: Each dice type is implemented as a separate, reusable module
- Type safety: Strongly typed API with compile-time guarantees
- Extensible: Easy to add new dice types and operations
- Performance: Optimized for both single rolls and batch operations
- Comprehensive error handling: Detailed error types for all failure cases
- Serialization support: All core types support Serde serialization
Supported Dice Types
- Standard polyhedral dice (
d):2d20,d6,4d10k3, etc. - FATE/Fudge dice (
f/df):4dF,8df, etc. - Exploding dice (
!):2d6!6,4d10!≥8, etc. - Infinite adding pools (
a):5a8k6m10(World of Darkness style) - Double cross pools (
c):5c8m10(Double Cross style) - Bonus/penalty dice (
p/b):d100p2,d20b1(CoC style) - Success-based pools: Count successes instead of summing
Installation
Add to your Cargo.toml:
[]
= "0.2"
For parser support (optional):
[]
= { = "0.2", = ["parser"] }
Quick Start
Basic Usage
use *;
// Roll 2d20 with advantage (keep highest)
let dice = new.keep_highest;
let result = dice.roll;
println!; // e.g., "2d20kh1 [17, 12] = 17"
// Roll FATE dice
let fate = new;
let result = fate.roll;
println!; // e.g., "4dF = +1"
// Roll exploding dice
let exploding = new; // Explode on 6
let result = exploding.roll;
println!; // e.g., "2d6!6 [6!, 4, 3] = 13"
Using Convenience Functions
use ;
// Standard dice
let result = d.keep_highest.roll;
// FATE dice
let result = f.roll;
// Exploding dice
let result = x.roll;
Dice Pools
use ;
// Infinite adding pool (World of Darkness style)
let pool = new // 5 dice, add on 8+
.with_success_threshold; // Success on 6+
let result = pool.roll;
println!;
// Double cross pool
let pool = new; // 5 dice, add on 8+
let result = pool.roll;
println!;
Parsing Dice Expressions (Optional Feature)
use *;
// Enable parser feature in Cargo.toml first
let expr = "2d20kh1 + 5";
let result = eval.unwrap;
println!; // e.g., "2d20kh1 + 5 = 22"
// Or parse without evaluating
let dice = new.parse.unwrap;
let result = dice.roll;
Advanced Usage
use *;
use ;
// Batch rolling
let dice = new;
let results = batch_roll;
// Calculate statistics
let stats = from_rolls;
println!;
println!;
// Format detailed output
for result in &results
API Overview
Core Types
Dice: Trait for all dice typesModifiableDice: Trait for dice that support operations (keep, drop, explode, etc.)DieRoll: Represents a single die roll with metadataRollResult: Complete result of a dice rollDiceContext: Context for rolling with configuration
Error Handling
use ;
match roll_safely
Configuration
use ;
let config = DiceConfig ;
let mut ctx = with_config;
let roll = ctx.roll_die;
OneDice Compatibility
NoctisRoll implements the complete OneDice V1 specification:
Supported Operators
d: Standard polyhedral dicea: Infinite adding poolc: Double cross poolf/df: FATE/Fudge dicek/q: Keep highest/lowestp/b: Bonus/penalty dice!: Exploding dicea: Success threshold (dice pool mode)
Supported Expressions
- Arithmetic:
+,-,*,/,%,^ - Comparisons:
>,<,>=,<=,==,!= - Ternary:
? : - Parentheses for grouping
- Functions:
min(),max(),abs(), etc.
Examples
See the examples/ directory for more complete examples:
Performance
NoctisRoll is optimized for performance:
- Zero allocations for simple dice rolls
- Lazy evaluation where possible
- Batch operations for multiple rolls
- Thread-safe implementation
Benchmarks are available in the benches/ directory.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
License
AGPL-3.0-only - See LICENSE for details.
Acknowledgments
- OneDice for the comprehensive standard
- All TRPG communities for inspiring this library
- Contributors and testers