dice_notation.md.txt 2.3 KB

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