kgscialdone / dice

A powerful and expressive dice expression parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dice

A powerful and expressive dice expression parser.

Installation

You can install Dice with JitPack (Gradle example shown below), check out the Releases page, or download the source code and build it yourself.

allprojects {
  repositories {
    // ...
    maven { url 'https://jitpack.io' }
  }
}

dependencies {
  implementation 'com.github.swordglowsblue:dice:master-SNAPSHOT'
}

API Docs

See here.

Expression Syntax

Most basic dice notation should work outright. See the page on Expression Syntax for details.

Examples

Parsing a dice expression

import com.swordglowsblue.dice.*

val expr: DiceExpr = DiceParser.parse("4d6")
  // => BasicDice(Const(4), Const(6))

Evaluating a parsed expression

val result: EvalResult = expr.eval()
result.expr     //: DiceExpr - The expression
result.value    //: Int - The result of the expression
result.subRolls //: List<RollResult> - Dice rolls made during evaluation

Working with RollResult

val rollResult: RollResult = expr.subRolls[0]
result.expr     //: Dice - The dice that were rolled
result.value    //: Int - The result of the roll
result.rolls    //: List<Int> - Individual die results
result.subRolls //: List<RollResult> - Other rolls made as part of this roll

About

A powerful and expressive dice expression parser


Languages

Language:Kotlin 100.0%