Trill is a Troll interpreter
Implemented in Python both as a package and for command line use.
Troll is a dice roll language made by Torben Mogensen
http://hjemmesider.diku.dk/~torbenm/Troll/
Rolling a single die: trill d12
Rolling multiple die: trill 3d6
from trill import trill
result, errors = trill("3d6")
See further examples in the examples folder.
make test
make coverage
Currently in a very early state. Most of the notation is not yet implemented. See the list below for what is, and what is not (supposed) to work yet.
(From summary on quick reference http://hjemmesider.diku.dk/~torbenm/Troll/quickRef.html)
- roll one dn (1 - n)
- roll m dn
- roll one zn (0 - n)
- roll m zn
- arithmetic on single value (+ - * / mod)
- sgn, sign of number
- sum, add up values in collection
- count values in collection
- Union of collections (U or @)
- Union of elements { }
- min and max in collection
- all minimal and all maximal values in collection
- median value in collection
- least n and
- largest n values in collection
- m samples of e ( # )
- range of values ( .. )
- choose value from collection
- pick n values from collection e
- filters (< <= > >= = =/=)
- drop elements
- keep elements
- multiset difference ( -- )
- remove duplicates ( different )
- conditional ( if-then-else )
- probability ( ?p )
- logical and ( & )
- logical not ( ! )
- bind x to value of e1 in e2 ( x := e1; e2 )
- foreach x in e1 do e2
- repeat x := e1 while/until e2
- accumulate x := e1 while/until e2
- function
- compositional
- call
- text box of single sample ( ' )
- text box of n samples ( n ' )
- combine text boxes horisontally ( || )
- combine text boxes vertically, left-aligned ( |> )
- combine text boxes vertically, right-aligned ( <| )
- combine text boxes, centre-aligned ( <> )
- Pair of e1,e2 ( [e1, e2])
- First component of pair ( %1 )
- Second component of pair ( %2 )
- x~v returns value of x if x is defined, else returns v