dice_notation.rst.txt 2.8 KB

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