dice_notation.rst 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. Dice Notation
  2. -------------
  3. *Dice notation* is nearly fully understood by pydice.
  4. Dice
  5. ~~~~
  6. Patterns describes here can be passed to the Dice.parse() class
  7. method, and will then return the corresponding Dice object.
  8. **`See Wikipedia for a complete definition.`_**
  9. Bases
  10. ^^^^^
  11. Die rolls are given in the form AdX. A (amount) and X (sides) are
  12. variables, separated by the letter “d”, which stands for die or dice.
  13. - A is the number of dice to be rolled (1 if omitted).
  14. - X is the number of faces of each die.
  15. If the final number is omitted, it is assumed to be a twenty. (This can
  16. be changed trough the class property Dice.DEFAULT\_SIDES)
  17. For example, if a game would call for a roll of d4 or 1d4 this would
  18. mean, “roll one 4-sided die.” ``3d6`` would mean, “roll three
  19. six-sided dice”
  20. Note: the ``D%`` notation is read as ``D100``
  21. Selective results
  22. ^^^^^^^^^^^^^^^^^
  23. The ``AdX`` pattern can be followed by ``Ln`` and/or ``Hn`` (‘L’ and ‘H’
  24. respectively stand for lowest and highest).
  25. In this case, the lowest/highest n scores will be discard when the dice
  26. will be rolled.
  27. *Eg: ``3D6L1`` will roll three 6-sided dice, and drop the lowest, while
  28. ``3D6H1`` will roll three 6-sided dice, and drop the highest.*
  29. Notes: \* If no number follow the ‘L’ or ‘H’, it is assumed to be a 1.
  30. \* ‘L’ and ‘H’ can be combined inside a single pattern.
  31. Patterns
  32. ~~~~~~~~
  33. Patterns describes here can be passed to the Pattern.parse() class
  34. method.
  35. ``AdX`` notations can be integrated in complex expressions.
  36. Any mathematical expression is allowed:
  37. ::
  38. >> 1d10+1d5+1
  39. >> 1d20-6
  40. >> 1d6*2
  41. >> 2d20//4
  42. >> 1d6*(1d4**2)
  43. Builtin python functions
  44. ^^^^^^^^^^^^^^^^^^^^^^^^
  45. Currently, the following python functions are allowed: ``abs``, ``max``,
  46. ``min``
  47. Repeat
  48. ^^^^^^
  49. The ``Rn(AdX)`` notation can be used to repat n times the ``AdX``
  50. command.
  51. For example, the pattern ``R3(2d6+2)`` will roll ``2d6+2`` three times.
  52. Examples
  53. ~~~~~~~~
  54. - ``1d6`` > Roll a 6-sided die
  55. - ``1d6+3`` > Roll a 6-sided die, then add 3
  56. - ``2*(1d6+3)`` > Roll a 6-sided die, add 3, then multiply by 2
  57. - ``3d6L2`` > Roll three 6-sided dice, and drop the two lowest.
  58. - ``R2(1d6+3)`` > Similar to ``1d6+3+1d6+3``
  59. - ``1d%`` > Similar to ``1d100``
  60. - ``d6`` > Similar to ``1d6``
  61. - ``min(1d6+10,3d6)`` > Keep the minimal score between ``1d6+10`` and
  62. ``3d6``
  63. .. _See Wikipedia for a complete definition.: https://en.wikipedia.org/wiki/Dice_notation