Dice Notation Tools for Java
This project aims to make the dice notation readable by Java applications, and for this it offers both a model representing it and a parser which can instantiate the model from dice notation expressions.
Created on the late 70s for Dungeons & Dragons, the dice notation has become a standard on tabletop games as it allows generating random values in concrete distributions with the help of simple formulas such as '2d6+5', which means "roll two dice, add their values and then add the number five to the result".
With the pass of years it has evolved, and while it never underwent a formal standardization process a core set of rules is kept among all the variations, mostly representing dice in a format such as '1d6', and the use of algebra operations like addition and subtraction.
Its usefulness is very clear, it allows working with specific random values distributions. And while this is no feat for a machine, which has better tools for it, the aim of the project is not actually handling those distributions, but giving a way for applications to work with the same tools a board game would have.
- ANTLR4 grammar
- Model for dice and dice notation, along classes to generate values from them
- Parser to create model instances from the notation
- Allows custom random number generation
- Arithmetic operations (addition, subtraction, multiplication, integer division)
- Parenthesis support
- Currently only the most basic operations (dice, numbers and additions or subtractions) are supported
The grammar is included among the ANTLR4 sample grammars.
- Dice Notation Tools CLI, a CLI to roll expressions through line command
Documentation is always generated for the latest release, kept in the 'master' branch:
Documentation is also generated from the latest snapshot, taken from the 'develop' branch:
The documentation site sources come along the source code (as it is a Maven site), so it is always possible to generate them using the following Maven command:
$ mvn verify site
The verify phase is required, as otherwise some of the reports won't be created.
The application is coded in Java, using Maven to manage the project.
JDK 8 or higher is required. All other dependencies are handled through Maven, and noted in the included POM file.
The recommended way to install the project is by setting up your preferred dependencies manager. To get the configuration information for this check the Bintray repository, or the Maven Central Repository.
If for some reason manual installation is necessary, just use the following Maven command:
$ mvn install
The project includes model, BNF grammar and parsers, which allow working with the most common dice notation expressions.
You may parse an expression, and generate a random value, like this:
final DiceParser parser; final RollHistory rolls; final DiceInterpreter<RollHistory> roller; parser = new DefaultDiceParser(); roller = new DiceRoller(); rolls = parser.parse("1d6+12", roller); // Prints the final result System.out.println(rolls.getTotalRoll());
For more examples and details check the docs.
Any kind of help with the project will be well received, and there are two main ways to give such help:
- Reporting errors and asking for extensions through the issues management
- or forking the repository and extending the project
Issues are managed at the GitHub project issues tracker, where any Github user may report bugs or ask for new features.
Getting the code
If you wish to fork or modify the code, visit the GitHub project page, where the latest versions are always kept. Check the 'master' branch for the latest release, and the 'develop' for the current, and stable, development version.
The project has been released under version 2.0 of the Apache License.