Tabletop RPG Dice rolling manager for handling Standard Dice Notation
Below is the grammer that is used by the parser generator to intepret inputs.
statement : expr | expr PLUS expr | expr MINUS expr | expr TIMES expr | expr DIVIDE expr expr : NUMBER | dice | func func : dice | dice KEEPHIGH | dice KEEPLOW | dice DROPHIGH | dice DROPLOW | dice KEEPHIGH NUMBER | dice KEEPLOW NUMBER | dice DROPHIGH NUMBER | dice DROPLOW NUMBER dice : NUMBER DIE NUMBER | NUMBER DIE TYPE PLUS : + MINUS : - TIMES : * DIVIDE : / NUMBER: [0-9]+ TYPE: [fF%] DIE : d KEEPHIGH: kh KEEPLOW: kl DROPHIGH: dh DROPLOW: dl
>>> from dicetray import Dicetray
>>> Dicetray('1d20 + 3').roll()
15
>>> Dicetray('4d6dl').roll()
10
>>> Dicetray('4d6kh3').roll()
12
>>> d = Dicetray('2d20kh + 1d4 + 3')
>>> d.result
>>> d.dice
set()
>>> d.roll()
18
>>> d.dice
{<Dice (d20): 14>, <Dice (d20): 14>, <Dice (d4): 1>}
>>> d.result
18