dart_dice_parser 1.1.1 copy "dart_dice_parser: ^1.1.1" to clipboard
dart_dice_parser: ^1.1.1 copied to clipboard

outdated

A dart library for parsing dice notation (like "2d6+4", "3d6", or "3d10 + 2d6 - 5d4")

dart_dice_parser #

Pub Package

A library for parsing dice notation

Supported syntax #

Supported notation:

  • AdX -- roll A dice of X sides, total will be returned as value
  • special dice variations:
    • AdF -- roll A fudge dice (sides: [-1, -1, 0, 0, 1, 1])
    • Ad% -- roll A percentile dice (equivalent to 1d100)
    • AD66 -- roll A D66, aka 1d6*10 + 1d6 (NOTE: this must use uppercase D, lowercase d will be interpreted as 66-sided die)
  • dropping high/low:
    • AdX-HN -- roll A X-sided dice, drop N highest
    • AdX-LN -- roll A X-sided dice, drop N lowest
  • addition/subtraction/multiplication and parenthesis are allowed
  • numbers must be integers, and division is is not supported.

examples:

  • 2d6 + 1 -- roll two six-sided dice, sum results and add one
  • 2d(2*10) + 3d100 -- roll 2 twenty-sided dice, sum results, add that to sum of 3 100-sided die
  • 1D66 -- roll a D66 -- aka two six-sided dice, multiply first by 10 and sum results
  • 1d% -- roll one percentile dice
  • 4dF -- roll four fudge dice ()
  • 2d20-H -- roll 2d20, drop highest (disadvantage)
  • 2d20-L -- roll 2d20, drop lowest (advantage)
  • 10d10-L3 -- roll 10d10, drop 10 lowest results

other dice notation info:

Usage #

A simple usage example:

    import 'package:dart_dice_parser/dart_dice_parser.dart';

    main() {
      var diceExpression = "2d6 + 1 + 3d10";

      print("$diceExpression : ${roll(diceExpression)}");
    }

    int roll(String diceStr) {
        var result = DiceParser().evaluate(diceStr);

        if (result.isFailure) {
            print("Failure:");
            print('\t${expression}');
            print('\t${' ' * (result.position - 1)}^-- ${result.message}');
            return 1;
        } else {
            return result.value;
        }
    }

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1
likes
0
pub points
26%
popularity

Publisher

unverified uploader

A dart library for parsing dice notation (like "2d6+4", "3d6", or "3d10 + 2d6 - 5d4")

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

logging, petitparser

More

Packages that depend on dart_dice_parser