Droll (droll v1.1.0) View Source
Simple implementation of standard dice notation
See The Wikipedia Page for more information.
Link to this section Summary
Functions
Parse a standard dice notation formula
Execute a roll based on a formula. See Droll.parse/1
for more information
Link to this section Functions
Specs
parse(iodata()) :: {:ok, Droll.Formula.t()} | {:error, String.t()}
Parse a standard dice notation formula
Examples:
iex> Droll.parse("d20")
{:ok, %Droll.Formula{num_dice: 1, num_sides: 20, modifier: 0, operation: :+}}
iex> Droll.parse("4d6")
{:ok, %Droll.Formula{num_dice: 4, num_sides: 6, modifier: 0, operation: :+}}
iex> Droll.parse("1d6+1")
{:ok, %Droll.Formula{num_dice: 1, num_sides: 6, modifier: 1, operation: :+}}
iex> Droll.parse("10d5-2")
{:ok, %Droll.Formula{num_dice: 10, num_sides: 5, modifier: 2, operation: :-}}
iex> Droll.parse("1d10/1")
{:ok, %Droll.Formula{num_dice: 1, num_sides: 10, modifier: 1, operation: :/}}
iex> Droll.parse("1d10x5")
{:ok, %Droll.Formula{num_dice: 1, num_sides: 10, modifier: 5, operation: :x}}
Execute a roll based on a formula. See Droll.parse/1
for more information