Coder Social home page Coder Social logo

dicenotation's Introduction

DiceNotation

DiceNotation is a simple parser / evaluator for a variant of "dice notation" similar to the version used in Dungeons and Dragons 3.5 that allows developers to support the use of dice notation in their own programs. It is written in C# and depends only on Portable Class Library functionality.

In addition, DiceNotation.MathNet uses the awesome MathNet.Numerics API to support pluggable random number generators; it too is PCL.

This is a fork of Chris Wagner's DiceNotation library, maintained by Ed Ropple.

Installation

DiceNotation is available on NuGet. To install, run the following command in the Package Manager Console:

PM> Install-Package EdCanHack.DiceNotation
PM> Install-Package EdCanHack.DiceNotation.MathNet

Usage

IDiceParser parser = new DiceParser();
DiceExpression dice = parser.Parse("3d6 + 12");

Int32 min = dice.Roll(new MinRoller); // 15
Int32 max = dice.Roll(new MaxRoller); // 30)

// This uses a singleton instance of System.Random across all rolls
// for all DiceExpressions; it's recommended that you instantiate an
// IDieRoller that preserves a given PRNG's seed and sequence.
Int32 ret = dice.Roll(); 
// Equivalent to "5 + d8 + 4d6k3"
var expression = new DiceExpression().Constant(5).Die(8).Dice(4, 6, choose: 3);

Dice Notation Examples

Expression Meaning
3d6 Roll three six-sided dice
4d6k3 Roll four six-sided dice, keep the three highest
2*2d8 Roll two eight-sided dice and multiply the result by two
5+d2 Roll a two-sided die (flip a coin) and add 5 to the result

Future Work

  • Results of dice rolls could be used as parameters to dice rolls (scalar, multiplicity, or choose).
  • The distributive property (3 * (2 + d6)) could be supported.
  • Better error handling on malformed expressions.

dicenotation's People

Contributors

eropple avatar

Watchers

 avatar  avatar

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.