README.mkdn 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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]. (One notable exception is non-standard Fate
  11. dice, i.e. "dF.1", which are not supported.)
  12. [1]: http://geekandsundry.com/shows/critical-role/
  13. [2]: https://en.wikipedia.org/wiki/Dice_notation#Standard_notation
  14. [3]: http://rpg.greenimp.co.uk/dice-roller/
  15. [4]: https://www.critdice.com/roll-advanced-dice
  16. ## Usage
  17. There are two ways to use this script. Either run it with any number
  18. of arguments, which will be concatenated and rolled, or run it with no
  19. arguments to enter interactive mode, where you can type a roll on each
  20. line and hit enter to roll it. In either case, the last line indicates
  21. the total roll, and all the lines before it indicate the individual
  22. dice rolls that led to it. Examples:
  23. ```bash
  24. # Single-roll command-line mode
  25. $ ./roll.py 2d4+2
  26. 2d4 rolled: [3,1], Total: 4
  27. 2017-11-26 15:54:47,849 INFO: Total roll for '2d4 + 2': 6
  28. # Interactive mode
  29. $ ./roll.py
  30. # Advantage roll in D&D, with a modifier
  31. Enter roll> 2d20-L+2
  32. 2d20-L rolled: 10 (dropped 5)
  33. 2017-11-26 15:55:37,826 INFO: Total roll for '2d20-L + 2': 12
  34. Enter roll> 6d6+6
  35. 6d6 rolled: [4,4,6,5,6,2], Total: 27
  36. 2017-11-26 16:26:43,989 INFO: Total roll for '6d6 + 6': 33
  37. Enter roll> d100
  38. d100 rolled: 16
  39. 2017-11-26 16:26:51,805 INFO: Total roll for 'd100': 16
  40. # Complex arithmetic expressions and non-standard dice are allowed
  41. Enter roll> d4 + 2d6 + 4 - 3d8 + 6d7/2
  42. d4 rolled: 1
  43. 2d6 rolled: [3,6], Total: 9
  44. 3d8 rolled: [4,5,5], Total: 14
  45. 6d7 rolled: [1,3,4,1,4,6], Total: 19
  46. 2017-11-26 16:27:01,238 INFO: Total roll for 'd4 + 2d6 + 4 - 3d8 + (6d7 / 2)': 9.5
  47. # Any arithmetic expression is allowd, even if it doesn't roll any dice
  48. Enter roll> 4 + 6^2 / 3
  49. 2017-11-26 16:48:46,121 INFO: Total roll for '4 + ((6 ^ 2) / 3)': 16
  50. # You can save specific rolls as named variables
  51. Enter roll> health_potion = 2d4 + 2
  52. 2017-11-26 16:53:56,188 INFO: Saving health_potion as '2d4 + 2'
  53. Enter roll> health_potion
  54. 2d4 rolled: [1,3], Total: 4
  55. 2017-11-26 16:54:44,287 INFO: Total roll for '2d4 + 2': 6
  56. # Variables can reference other variables
  57. Enter roll> greater_health_potion = health_potion + health_potion
  58. 2017-11-26 16:54:12,684 INFO: Saving double_health_potion as 'health_potion + health_potion'
  59. Enter roll> greater_health_potion
  60. 2d4 rolled: [4,4], Total: 8
  61. 2d4 rolled: [4,3], Total: 7
  62. 2017-11-26 16:55:30,455 INFO: Total roll for '(2d4 + 2) + (2d4 + 2)': 19
  63. # Show currently defined variables
  64. Enter roll> vars
  65. 2017-11-26 16:59:15,241 INFO: Currently defined variables:
  66. greater_health_potion = 'health_potion + health_potion'
  67. health_potion = '2d4 + 2'
  68. # Delete a variable
  69. Enter roll> del greater_health_potion
  70. 2017-11-26 16:59:40,713 INFO: Deleting saved value for 'greater_health_potion'.
  71. # Reroll ones once
  72. Enter roll> 4d4r
  73. 4d4r rolled: [1r,2,2,3], Total: 8
  74. 2017-11-26 17:01:41,592 INFO: Total roll for '4d4r': 8
  75. # Reroll ones indefinitely
  76. Enter roll> 4d4R
  77. 4d4R rolled: [3,3,2R,4], Total: 12
  78. 2017-11-26 17:01:53,784 INFO: Total roll for '4d4R': 12
  79. # Exploding dice
  80. Enter roll> 6d6!
  81. 6d6! rolled: [1,6!,3,3,4,5,6!,5], Total: 33
  82. 2017-11-26 16:30:43,003 INFO: Total roll for '6d6!': 33
  83. # Explode any roll greater than 3
  84. Enter roll> 6d6!>3
  85. 6d6!>3 rolled: [4!,4!,6!,2,2,5!,2,1,6!,4!,1,1], Total: 38
  86. 2017-11-26 16:32:18,204 INFO: Total roll for '6d6!>3': 38
  87. # Penetrating dice
  88. Enter roll> 6d6!p
  89. 6d6!p rolled: [1,6!p,1,5,6!p,2,1,5], Total: 27
  90. 2017-11-26 16:32:48,727 INFO: Total roll for '6d6!p': 27
  91. # Fate dice
  92. Enter roll> 4dF+2
  93. 4dF rolled: [0,0,0,1], Total: 1
  94. 2017-11-26 16:34:11,533 INFO: Total roll for '4dF + 2': 3
  95. # Enter 'help' for other non-roll commands
  96. Enter roll> quit
  97. 2017-11-26 16:29:47,624 INFO: Quitting.
  98. ```
  99. As you can see, it not only reports the total for each roll, but all
  100. the individual dice rolls as well, so you can understand how it came
  101. up with the total. This also lets you figure out whether you rolled a
  102. natural 20 or natural 1 on the die.
  103. ## Known Issues
  104. * There is no sanity checking for dice roll effects that will never
  105. take effect, such as exploding a d6 on 7 (i.e. `d6!=7)
  106. * Error messages are pretty much just reported as is, with no attempt
  107. to explain or contextualize them.
  108. * Nonstandard Fate dice (i.e. "dF.1") are not supported.