introduction.rst 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. XDice
  2. =====
  3. Presentation
  4. ------------
  5. *xdice* is a lightweight python library for managing dice, scores, and
  6. dice-notation patterns.
  7. It allows to easily interpret literal expressions as rolls of dice
  8. (‘1d6’, ‘3d4+3’, ‘12d6+1d4’…etc.), then manipulate the results.
  9. Python Versions
  10. ~~~~~~~~~~~~~~~
  11. DiceRollParser has been tested with python 3.3+
  12. Examples
  13. ~~~~~~~~
  14. ::
  15. import dice
  16. # Roll dices with dice.rolldice()
  17. score = dice.rolldice(6, amount=2)
  18. # manipulate 'score' as an integer
  19. print(score)
  20. >> 11
  21. print(score * 2)
  22. >> 22
  23. print(score == 11)
  24. >> True
  25. # Or iterate over the results
  26. for result in score:
  27. print(result)
  28. >> 5
  29. >> 6
  30. # Parse patterns with dice.roll()
  31. ps = dice.roll("2d6+18")
  32. print(ps)
  33. >> 28
  34. print(ps.format())
  35. >> '[5,6]+18'
  36. ps = dice.roll("6D%L2")
  37. print(ps)
  38. >> 315
  39. print(ps.format(verbose=True))
  40. >> '6D%L2(scores:[80, 70, 76, 89], dropped:[2, 49])'
  41. Contribution
  42. ~~~~~~~~~~~~
  43. Any opinion / contribution is welcome, please contact us.
  44. Installation
  45. ~~~~~~~~~~~~
  46. ::
  47. pip install xdice
  48. License
  49. ~~~~~~~
  50. *xdice* is under GNU License
  51. Tags
  52. ~~~~
  53. ::
  54. dice roll d20 game random parser dices role board