README.mkdn 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # roll.py: A dice-rolling simulator for RPGs
  2. This was a weekend hobby project inspired by [Critical Role][1] and
  3. other D&D shows and podcasts. While a dice simulator is no substitute
  4. for physically rolling real dice, it might be useful for anyone who's
  5. on the go or otherwise unable to access their dice and a flat surface
  6. to roll them on (or for new players who want to try out RPGs without
  7. having to spend money on dice first). It supports almost everything in
  8. the ["Standard Notation"][2] section of the Wikipedia page on dice
  9. notation, as well as the syntax in this online [RPG Dice Roller][3]
  10. and this [Android App][4].
  11. [1]: http://geekandsundry.com/shows/critical-role/
  12. [2]: https://en.wikipedia.org/wiki/Dice_notation#Standard_notation
  13. [3]: http://rpg.greenimp.co.uk/dice-roller/
  14. [4]: https://www.critdice.com/roll-advanced-dice
  15. ## Usage
  16. There are two ways to use this script. Either run it with any number
  17. of arguments, which will be concatenated and rolled, or run it with no
  18. arguments to enter interactive mode, where you can type a roll on each
  19. line and hit enter to roll it. In either case, the last line indicates
  20. the total roll, and all the lines before it indicate the individual
  21. dice rolls that led to it. Examples:
  22. ```bash
  23. # Single-roll command-line mode
  24. $ ./roll.py 2d4+2
  25. 2d4 rolled: [3,1], Total: 4
  26. 2017-11-26 15:54:47,849 INFO: Total roll for '2d4 + 2': 6
  27. # Interactive mode
  28. $ ./roll.py
  29. # Advantage roll in D&D, with a modifier
  30. Enter roll> 2d20-L+2
  31. 2d20-L rolled: 10 (dropped 5)
  32. 2017-11-26 15:55:37,826 INFO: Total roll for '2d20-L + 2': 12
  33. Enter roll> 6d6+6
  34. 6d6 rolled: [4,4,6,5,6,2], Total: 27
  35. 2017-11-26 16:26:43,989 INFO: Total roll for '6d6 + 6': 33
  36. Enter roll> d100
  37. d100 rolled: 16
  38. 2017-11-26 16:26:51,805 INFO: Total roll for 'd100': 16
  39. # Complex arithmetic expressions and non-standard dice are allowed
  40. Enter roll> d4 + 2d6 + 4 - 3d8 + 6d7/2
  41. d4 rolled: 1
  42. 2d6 rolled: [3,6], Total: 9
  43. 3d8 rolled: [4,5,5], Total: 14
  44. 6d7 rolled: [1,3,4,1,4,6], Total: 19
  45. 2017-11-26 16:27:01,238 INFO: Total roll for 'd4 + 2d6 + 4 - 3d8 + (6d7 / 2)': 9.5
  46. # Any arithmetic expression is allowd, even if it doesn't roll any dice
  47. Enter roll> 4 + 6^2 / 3
  48. 2017-11-26 16:48:46,121 INFO: Total roll for '4 + ((6 ^ 2) / 3)': 16
  49. # You can save specific rolls as named variables
  50. Enter roll> health_potion = 2d4 + 2
  51. 2017-11-26 16:53:56,188 INFO: Saving health_potion as '2d4 + 2'
  52. Enter roll> health_potion
  53. 2d4 rolled: [1,3], Total: 4
  54. 2017-11-26 16:54:44,287 INFO: Total roll for '2d4 + 2': 6
  55. # Variables can reference other variables
  56. Enter roll> greater_health_potion = health_potion + health_potion
  57. 2017-11-26 16:54:12,684 INFO: Saving double_health_potion as 'health_potion + health_potion'
  58. Enter roll> greater_health_potion
  59. 2d4 rolled: [4,4], Total: 8
  60. 2d4 rolled: [4,3], Total: 7
  61. 2017-11-26 16:55:30,455 INFO: Total roll for '(2d4 + 2) + (2d4 + 2)': 19
  62. # Show currently defined variables
  63. Enter roll> vars
  64. 2017-11-26 16:59:15,241 INFO: Currently defined variables:
  65. greater_health_potion = 'health_potion + health_potion'
  66. health_potion = '2d4 + 2'
  67. # Delete a variable
  68. Enter roll> del greater_health_potion
  69. 2017-11-26 16:59:40,713 INFO: Deleting saved value for 'greater_health_potion'.
  70. # Reroll ones once
  71. Enter roll> 4d4r
  72. 4d4r rolled: [1r,2,2,3], Total: 8
  73. 2017-11-26 17:01:41,592 INFO: Total roll for '4d4r': 8
  74. # Reroll ones indefinitely
  75. Enter roll> 4d4R
  76. 4d4R rolled: [3,3,2R,4], Total: 12
  77. 2017-11-26 17:01:53,784 INFO: Total roll for '4d4R': 12
  78. # Exploding dice
  79. Enter roll> 6d6!
  80. 6d6! rolled: [1,6!,3,3,4,5,6!,5], Total: 33
  81. 2017-11-26 16:30:43,003 INFO: Total roll for '6d6!': 33
  82. # Explode any roll greater than 3
  83. Enter roll> 6d6!>3
  84. 6d6!>3 rolled: [4!,4!,6!,2,2,5!,2,1,6!,4!,1,1], Total: 38
  85. 2017-11-26 16:32:18,204 INFO: Total roll for '6d6!>3': 38
  86. # Penetrating dice
  87. Enter roll> 6d6!p
  88. 6d6!p rolled: [1,6!p,1,5,6!p,2,1,5], Total: 27
  89. 2017-11-26 16:32:48,727 INFO: Total roll for '6d6!p': 27
  90. # Fate dice
  91. Enter roll> 4dF+2
  92. 4dF rolled: [0,0,0,1], Total: 1
  93. 2017-11-26 16:34:11,533 INFO: Total roll for '4dF + 2': 3
  94. # Enter 'help' for other non-roll commands
  95. Enter roll> quit
  96. 2017-11-26 16:29:47,624 INFO: Quitting.
  97. ```
  98. As you can see, it not only reports the total for each roll, but all
  99. the individual dice rolls as well, so you can understand how it came
  100. up with the total. This also lets you figure out whether you rolled a
  101. natural 20 or natural 1 on the die for critical hits and misses, and
  102. if your damage roll involves multiple different kinds of damage, it
  103. lets you figure out how much of each damage type was dealt.