Coder Social home page Coder Social logo

ndice's Introduction

ndice

Role a nice dice (or [n|d]ice?)

Header image

Table of Contents

About

ndice is a cli dice roller and dice-rolling library.

Dices are writen in the format ${number}${exploding}d{$sides}, e.g. 1d6 means 1 six-sided dice. There's no limit to sides so a non-existing dice like 1d13 can be rolled.

  • Each space-speparated argument is counted as one dice notation.
  • Dices can be mixed, so ndice 1d6 2d8 4d10 works.
  • Invalid arguments are ignored.

Installation

⬆️ Back to Top

Binary

Download a pre-compiled binary from the release page

Cargo

Install with cargo:

$ cargo install ndice

Usage (CLI)

⬆️ Back to Top

$ ndice [dice]

Examples:

# Roll 1 six-sided dice
$ ndice 1d6
Rolled: ["d6 => 1"]
Result: 1
# Roll 2 8 sided dice and 2 four sided dice
$ ndice 2d8 2d4
Rolled: ["d8 => 6", "d8 => 3", "d4 => 1", "d4 => 1"]
Result: 11

Exploding dice

An exploding dice is a dice that is re-rolled when the highest possible value is rolled.

To roll a exploding dice use ed instead of d as argument.

  • 1d6 -> normal d6
  • 1ed6 -> exploding d6

Modifier

A positive or negative modifier can be added to each dice.

  • 1d6+2 -> add +2 to the result of rolling a d6
  • 1d20-4 -> subtract 4 from the result of rolling a d20

Usage (Library)

ndice can be used as library.

Add the library to Cargo.toml

[dependencies]
ndice = 1.0

Optional JSON features can be enabled with a flag.

[dependencies]
ndice = { version = "1.0", features = ["json"] }

And finally, call the two functions: ndice::parse_dices and ndice::roll_dices.

fn my_func() {
  let args: Vec<String> = vec![String::from("1d6"), String::from("2d4"), String::from("1ed4")];
  let dice_in_hand = ndice::parse_dices(args).unwrap();
  let roll = ndice::roll_dices(dice_in_hand);
  println!("{}", roll);
}

See src/bin.rs for an example implementation.

Contributing

⬆️ Back to Top

We love and welcome every form of contribution.

Where to start?

Here are some good places to start:

Tooling

  • mktoc is used for table of content generation in the README.md (neat!)

Install dev build

Sometimes it's nice to install a specific version of ndice, this can be done with the following command:

# install specific commit
cargo install --git https://github.com/KevinGimbel/ndice--force --rev $COMMIT_ID
# install branch
cargo install --git https://github.com/KevinGimbel/ndice--force --branch $BRANCH_NAME

License

⬆️ Back to Top

MIT, see LICENSE file.

ndice's People

Contributors

kevingimbel avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

ndice's Issues

Modifier values

+ or - values to be added to a result.

Example:

$ ndice 3d6 +3
$ ndice 1d4 -1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.