dicey

Crates.iodicey
lib.rsdicey
version1.1.0
sourcesrc
created_at2021-09-11 13:03:50.337239
updated_at2021-09-11 21:20:16.88861
descriptionSimple library for parsing dice strings of the form "adx,bdy,cdz", where a, b, & c are quantity of dice and x, y, & z are the number of faces on those dice; e.g., 5d6 represents 5 6-sided dice, as in the game Yahtzee
homepagehttps://github.com/kinseywk/dicey
repositoryhttps://github.com/kinseywk/dicey
max_upload_size
id449713
size10,743
kinseywk (kinseywk)

documentation

https://github.com/kinseywk/dicey

README

Dicey

A simple library for parsing dice strings (e.g., 1d20, 2d12, 3d8) you might see in tabletop games like Dungeons & Dragons.

Provides a single struct, DieRoll, and single function, parse(&str) that converts an input string to a list of DieRolls.

Usage:

use dicey::parse;
use rand::*;

fn main() {
	if let Some(mut rolls) = parse("5d6") {
		if let Some(roll) = rolls.pop() {
			for _ in 0..roll.quantity {
				println!("{}", random::<u8>() % roll.faces + 1);
			}
		}
	}
}

Also contains the dicey command line utility for simulating dice rolls from dice strings.

Examples:

  • Coin flip (heads = 1, tails = 2): dicey 1d2

  • Yahtzee: dicey 5d6

  • D&D initiative & saving throws: dicey 1d20

  • Pathfinder Magic Missile damage: dicey 1d4+1

  • Various dice w/ bonuses & penalties: dicey 1d4,2d6+1,3d8-2

Commit count: 10

cargo fmt