index.md.txt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. **xdice**
  2. *xdice* is a lightweight python library for managing dice, scores, and dice-notation patterns.
  3. It allows to easily interpret literal expressions as rolls of dice ('1d6', '3d4+3', '12d6+1d4'...etc.), then manipulate the results.
  4. #### Python Versions
  5. DiceRollParser has been tested with python 3.3+
  6. #### Examples:
  7. import dice
  8. ## Roll simple dices with **rolldice()**
  9. score = rolldice(6, amount=2)
  10. # manipulates score as an integer
  11. print( score, score * 2, score == 11 )
  12. >> 11 22 True
  13. # Iterates over the results
  14. for result in score:
  15. print(result)
  16. >> 5
  17. >> 6
  18. # Parse patterns with **roll()**
  19. ps = roll("2d6+18")
  20. print( ps, ps.format() )
  21. >> 28 '[5,6]+18'
  22. #### CLI
  23. Run `python roll.py [options] <expr>`
  24. Usage:
  25. roll [options] <expr>
  26. Options:
  27. -s Numeric score only
  28. -h --help Displays help message
  29. --version Displays current xdice version
  30. #### CONTRIBUTION
  31. Any opinion / contribution is welcome, please contact us.
  32. #### TO INSTALL
  33. pip install xdice
  34. #### License
  35. *xdice* is under GNU License
  36. #### Author
  37. Olivier Massot, 2017, with *Cro-ki Lab*
  38. #### Tags
  39. dice roll d20 game random parser dices role board