README.mkdn 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # roll.py: A dice-rolling simulator for RPGs
  2. This was a weekend hobby project inspired by
  3. [Critical Role](http://geekandsundry.com/shows/critical-role/) and
  4. other D&D shows and podcasts. While a dice simulator is no substitute
  5. for physically rolling real dice, it might be useful for anyone who's
  6. on the go or otherwise unable to access their dice or a flat surface
  7. to roll them on (or for new players who want to try out RPGs without
  8. having to spend money on dice first). It supports pretty much
  9. everything under the
  10. ["Standard Notation" section of the Wikipedia page on dice notation](https://en.wikipedia.org/wiki/Dice_notation#Standard_notation).
  11. ## Usage
  12. There are two ways to use this script. Either run it with any number
  13. of arguments, which will be concatenated and rolled, or run it with no
  14. arguments to enter interactive mode, where you can type a roll on each
  15. line and hit enter to roll it. In either case, the last line indicates
  16. the total roll, and all the lines before it indicate the individual
  17. dice rolls that led to it. Examples:
  18. ```bash
  19. # Single-roll command-line mode
  20. $ ~/temp/roll.py 2d4+2
  21. 2016-03-13 14:43:16,690 INFO: Rolling 2d4+2
  22. 2016-03-13 14:43:16,691 INFO: 2d4+2 rolled: 8
  23. (Individual rolls: [2, 4])
  24. 2016-03-13 14:43:16,691 INFO: Total roll: 8
  25. # Interactive mode
  26. $ ~/temp/roll.py
  27. Enter roll> 2d20-L+2
  28. 2016-03-13 15:17:24,496 INFO: Rolling 2d20-L+2
  29. 2016-03-13 15:17:24,496 INFO: 2d20-L+2 rolled: 22 (NATURAL 20)
  30. (Individual rolls: [20]; Dropped low: [5]; Original rolls: [5, 20])
  31. 2016-03-13 15:17:24,496 INFO: Total roll: 22
  32. Enter roll> 6d6+6
  33. 2016-03-13 14:43:34,468 INFO: Rolling 6d6+6
  34. 2016-03-13 14:43:34,468 INFO: 6d6+6 rolled: 25
  35. (Individual rolls: [4, 1, 1, 3, 4, 6])
  36. 2016-03-13 14:43:34,469 INFO: Total roll: 25
  37. Enter roll> d100
  38. 2016-03-13 14:43:41,854 INFO: Rolling d100
  39. 2016-03-13 14:43:41,854 INFO: d100 rolled: 67
  40. 2016-03-13 14:43:41,855 INFO: Total roll: 67
  41. Enter roll> d4 + 2d6 + 4 - 3d8 + 6d7/2
  42. 2016-03-13 14:49:17,237 INFO: Rolling d4 + 2d6 + 4 - 3d8 + 6d7/2
  43. 2016-03-13 14:49:17,237 INFO: d4 rolled: 4
  44. 2016-03-13 14:49:17,238 INFO: 2d6 rolled: 7
  45. (Individual rolls: [6, 1])
  46. 2016-03-13 14:49:17,238 INFO: 3d8 rolled: 13
  47. (Individual rolls: [6, 5, 2])
  48. 2016-03-13 14:49:17,238 INFO: 6d7 rolled: 19
  49. (Individual rolls: [2, 4, 7, 2, 1, 3])
  50. 2016-03-13 14:49:17,238 INFO: Total roll: 11
  51. Enter roll> 4 + 5
  52. 2016-03-13 14:48:13,823 INFO: Rolling 4 + 5
  53. 2016-03-13 14:48:13,823 INFO: Total roll: 9
  54. Enter roll> exit
  55. ```
  56. As you can see, it not only reports the total, but all the individual
  57. dice rolls, so if you made a mistake on a modifier or something, you
  58. don't have to re-roll the entire thing, you can change the modifier
  59. and re-add the existing dice rolls manually. Also, as a special
  60. feature, it tells you when you get a natural 1 or a natural 20 on a
  61. singular d20 roll.
  62. Notice the last few examples that demonstrate:
  63. * arbitrarily complex arithmetic expressions involving any number and
  64. kind of dice and any number of modifiers, as well as multiplication
  65. and division (useful for resistances and critical hits)
  66. * physically impossible dice, like d7
  67. * simple constant expressions that don't involve any dice rolls.
  68. (This last feature is useful for re-computing a mis-typed modifier
  69. without re-rolling the dice.)
  70. ## Rolling with advantage/disadvantage and dropping rolls
  71. Some RPGs have a concept of "advantage" or "disadvantage", which just
  72. means rolling two of the same die and dropping either the lower of the
  73. two (for advantage) or the higher (for disadvantage). You can do this
  74. by appending `-L` to drop the lowest roll and `-H` to drop the highest
  75. one. More generally, you can drop any number of low or high rolls by
  76. adding a number after the `H` or `L`. One of the examples above shows
  77. a d20 roll with a +5 modifier and advantage, which is expressed as
  78. "2d20-L+6". When dropping dice, all the original rolls are reported,
  79. as well as which ones were dropped, so you always have a full audit
  80. trail in case your DM asks you what your dice rolls were.