|
2 | 2 | dice
|
3 | 3 | ====
|
4 | 4 |
|
5 |
| -A library for parsing and evaluating dice notation. |
| 5 | +A library and command line tool for parsing and evaluating dice notation. |
6 | 6 |
|
7 |
| -Todo |
8 |
| -==== |
| 7 | +Usage |
| 8 | +===== |
9 | 9 |
|
10 |
| -* Unary and binary operators |
11 |
| -* Console and module API functions |
| 10 | +From the command line:: |
12 | 11 |
|
13 |
| -Notes |
14 |
| -===== |
| 12 | + roll 3d6 |
| 13 | + |
| 14 | +From python:: |
| 15 | + |
| 16 | + import dice |
| 17 | + dice.roll('3d6') |
| 18 | + |
| 19 | +Notation |
| 20 | +======== |
| 21 | + |
| 22 | +The expression works like a simple equation parser with some extra operators. |
| 23 | + |
| 24 | +*The following operators are listed in order of precedence.* |
| 25 | + |
| 26 | +The dice ('d') operator takes an amount (A) and a number of sides (S), and |
| 27 | +returns a list of A random numbers between 1 and S. For example: ``4d6`` may |
| 28 | +return ``[6, 3, 2, 4]``. |
| 29 | + |
| 30 | +If A is not specified, it is assumed you want to roll a single die. |
| 31 | +``d6`` is equivalent to ``1d6``. |
| 32 | + |
| 33 | +Basic integer operations are available: ``16 / 8 * 4 + 2 - 1 -> 9``. |
15 | 34 |
|
16 |
| -Some rough notes on how I want the API to look: |
| 35 | +A set of rolls can be turned into an integer with the total (``t``) operator. |
| 36 | +``6d1t`` will return ``6`` instead of ``[1, 1, 1, 1, 1, 1]``. Applying |
| 37 | +integer operations to a list of rolls will total them automatically. |
17 | 38 |
|
18 |
| -:: |
| 39 | +A set of dice rolls can be sorted with the sort (``s``) operator. ``4d6s`` |
| 40 | +will not change the return value, but the dice will be sorted from lowest to |
| 41 | +highest. |
19 | 42 |
|
20 |
| - >>> d = Dice('2d6') |
21 |
| - Dice("Two six-sided dice") |
22 |
| - >>> d.roll() |
23 |
| - Roll(5, 5, sides=6) |
24 |
| - >>> b = Bag('two six-sided dice', 'six-sided die', '4d2', (3,3), Dice('d1')) |
25 |
| - >>> repr(b) |
26 |
| - Bag((3,6), (4,2), (3,3)) |
27 |
| - >>> str(b) |
28 |
| - "3d6, 4d2, 1d1" |
| 43 | +The lowest or highest rolls can be selected with ``^`` and ``v``. ``6d6^3`` |
| 44 | +will keep the highest 3 rolls, whereas ``6d6v3`` will select the lowest 3 |
| 45 | +rolls. |
29 | 46 |
|
30 | 47 | Licence
|
31 | 48 | =======
|
|
0 commit comments