dart_dice_parser 3.0.2 dart_dice_parser: ^3.0.2 copied to clipboard
A dart library for parsing dice notation (e.g. "2d6+4"). Supports advantage/disadvantage, exploding die, and many other variations.
dart_dice_parser #
A dart library for parsing dice notation (e.g. "2d6+4"). Supports advantage/disadvantage, exploding die, and many other variations.
Examples #
2d6 + 1
-- roll two six-sided dice, sum results and add one2d(2*10) + 3d100
-- roll 2 twenty-sided dice, sum results, add that to sum of 3 100-sided die1D66
-- roll a D66 -- aka two six-sided dice, multiply first by 10 and sum results1d%
-- roll one percentile dice4dF
-- roll four fudge dice2d20-H
-- roll 2d20, drop highest (disadvantage)2d20-L
-- roll 2d20, drop lowest (advantage)4d20-H-L
-- roll 4d20, drop highest and lowest10d10-L3
-- roll 10d10, drop 3 lowest results(2d10+3d20)-L3
-- roll 2d10 and 3d20, combine the two results lists, and drop lowest 3 results20d10-<3->8#
-- roll 20 d10, drop any less than 3 or greater than 8 and count the number of remaining dice2d6 * 2
-- roll 2d6, multiply result by 3
Supported notation #
-
AdX
-- rollA
dice ofX
sides, total will be returned as value -
special dice variations:
-
AdF
-- rollA
fudge dice (sides:[-1, -1, 0, 0, 1, 1]
) -
Ad%
-- rollA
percentile dice (equivalent to1d100
) -
AD66
-- rollA
D66, aka1d6*10 + 1d6
(NOTE: you must use uppercaseD66
, lowercased66
will be interpreted as 66-sided die) -
exploding dice
Ad!X
-- rollA
X
-sided dice, explode if max is rolled (re-roll and include in results)- the dice roller won't explode dice more than 100 times.
Ad!!X
-- rollA
X
-sided dice, explode only once (limited explosion)
-
-
modifying the roll results:
- dropping dice:
AdX-HN
-- rollA
X
-sided dice, drop N highestAdX-LN
-- rollA
X
-sided dice, drop N lowestAdX->B
-- rollA
X
-sided dice, drop any results greater than BAdX-<B
-- rollA
X
-sided dice, drop any results less than BAdX-=B
-- rollA
X
-sided dice, drop any results equal to B- NOTE: the drop operators have higher precedence than
the arithmetic operators, so
4d10-L2+2
is equivalent to(4d10-L2)+2
- cap/clamp:
AdXC<B
-- rollA
X
-sided dice, change any value less than B to BAdXC>B
-- rollA
X
-sided dice, change any value greater than B to B
- dropping dice:
-
operations on dice rolls:
- counting:
AdX#
-- how many results? (useful for20d10-<2->8#
-- roll 20 d10, drop <2 and >8, how many are left?)AdX#>B
-- rollA
X
-sided dice, count any greater than BAdX#<B
-- rollA
X
-sided dice, count any less than BAdX#=B
-- rollA
X
-sided dice, count any equal to B
- counting:
-
addition/subtraction/multiplication and parenthesis are allowed
-
numbers must be integers
-
division is is not supported.
Usage #
A simple usage example:
import 'package:dart_dice_parser/dart_dice_parser.dart';
main() {
var diceExpression = "2d6 + 1 + 3d10";
print("$diceExpression : ${DiceParser().roll(diceExpression)}");
}
CLI Usage #
foo@bar$ dart run example/main.dart '3d6'
1: 9
# run N number of rolls
foo@bar$ dart run example/main.dart -n 6 '3d6'
1: 6
2: 8
3: 15
4: 15
5: 8
6: 10
# show stats
foo@bar$ dart run example/main.dart -s '3d6'
{min: 3, max: 18, count: 10000, histogram: {3: 41, 4: 151, 5: 275, 6: 473, 7: 700, 8: 991, 9: 1182, 10: 1292, 11: 1270, 12: 1084, 13: 924, 14: 678, 15: 472, 16: 274, 17: 151, 18: 42}, mean: 10.5, stddev: 2.96}
Features and bugs #
Please file feature requests and bugs at the issue tracker.