Git Product home page Git Product logo

d20's Introduction

D20

Need to evaluate dice notation in Swift? This package is for you.

Examples

let roll = Roll("1d20")!.roll()
roll.result
// $R0: Int = 18

let roll = Roll("3d8+1d6")!.roll()
roll.result
// $R0: Int = 19
roll.expression
// $R1: String = "1+6+7+5"

// Percentage die shorthand is also supported.
let roll = Roll("d%")

D(20).average
// $R0: Double = 10.5

The rest of the API is pretty self-explanatory. Dice and Rolls have attributes for accessing the max, half and average values of their rolls. Use the roll() function to actually throw the dice on both of these types and get some random values.

CLI

This package also includes a small CLI to roll the dice directly in your terminal.

$ d20 2d6+4
# 14 (6+4)+4

$ alias dagger='d20 1d4+2'
$ dagger
# 6 (4)+2
# CRIT!

# Invoke it without an argument to enter REPL mode.
$ d20
> d4
3 (3)
> 2d4
6 (2+4)

Installing it is easy. Just run the following after cloning the repo.

$ swift build -c release
$ cp .build/release/d20 /usr/local/bin/d20

Logo Credits

D20 by Lonnie Tapscott from the Noun Project

d20's People

Contributors

kiliankoe avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

d20's Issues

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.