dice_notation.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Dice Notation &#8212; xdice 1.0.0 documentation</title>
  7. <link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: './',
  12. VERSION: '1.0.0',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true,
  16. SOURCELINK_SUFFIX: '.txt'
  17. };
  18. </script>
  19. <script type="text/javascript" src="_static/jquery.js"></script>
  20. <script type="text/javascript" src="_static/underscore.js"></script>
  21. <script type="text/javascript" src="_static/doctools.js"></script>
  22. <link rel="index" title="Index" href="genindex.html" />
  23. <link rel="search" title="Search" href="search.html" />
  24. <link rel="next" title="Command-Line" href="cli.html" />
  25. <link rel="prev" title="Introduction" href="introduction.html" />
  26. <link rel="stylesheet" href="_static/custom.css" type="text/css" />
  27. <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
  28. </head>
  29. <body>
  30. <div class="document">
  31. <div class="documentwrapper">
  32. <div class="bodywrapper">
  33. <div class="body" role="main">
  34. <div class="section" id="dice-notation">
  35. <h1>Dice Notation<a class="headerlink" href="#dice-notation" title="Permalink to this headline">¶</a></h1>
  36. <p><em>Dice notation</em> is nearly fully understood by pydice.</p>
  37. <p><em>xdice</em> is case insensitive.</p>
  38. <div class="section" id="dice">
  39. <h2>Dice<a class="headerlink" href="#dice" title="Permalink to this headline">¶</a></h2>
  40. <blockquote>
  41. <div>Patterns describes here can be passed to the Dice.parse() class
  42. method, and will then return the corresponding Dice object.</div></blockquote>
  43. <p><a class="reference external" href="https://en.wikipedia.org/wiki/Dice_notation">See Wikipedia for a complete definition.</a></p>
  44. <div class="section" id="bases">
  45. <h3>Bases<a class="headerlink" href="#bases" title="Permalink to this headline">¶</a></h3>
  46. <p>Die rolls are given in the form AdX. A (amount) and X (sides) are
  47. variables, separated by the letter “d”, which stands for die or dice.</p>
  48. <ul>
  49. <li><p class="first">A is the number of dice to be rolled (1 if omitted).</p>
  50. </li>
  51. <li><p class="first">X is the number of faces of each die.</p>
  52. <blockquote>
  53. <div><p>For example, if a game would call for a roll of d4 or 1d4 this would
  54. mean, “roll one 4-sided die.” 3d6 would mean, “roll three
  55. six-sided dice”</p>
  56. </div></blockquote>
  57. </li>
  58. </ul>
  59. </div>
  60. <div class="section" id="default-values">
  61. <h3>Default values<a class="headerlink" href="#default-values" title="Permalink to this headline">¶</a></h3>
  62. <p>If the A value is omitted, it is assumed to be a 1.</p>
  63. <p>If the X value is omitted, it is assumed to be a 20.
  64. This behavior can be modified trough the class property Dice.DEFAULT_SIDES.</p>
  65. </div>
  66. <div class="section" id="d-notation">
  67. <h3>D% Notation<a class="headerlink" href="#d-notation" title="Permalink to this headline">¶</a></h3>
  68. <p>The <code class="docutils literal"><span class="pre">D%</span></code> notation is allowed, and read as <code class="docutils literal"><span class="pre">D100</span></code>.</p>
  69. </div>
  70. <div class="section" id="selective-results">
  71. <h3>Selective results<a class="headerlink" href="#selective-results" title="Permalink to this headline">¶</a></h3>
  72. <p>The <code class="docutils literal"><span class="pre">AdX</span></code> pattern can be followed by <code class="docutils literal"><span class="pre">Ln</span></code> and/or <code class="docutils literal"><span class="pre">Hn</span></code> (‘L’ and ‘H’
  73. respectively stand for lowest and highest).</p>
  74. <p>In this case, the lowest/highest n scores will be discard when the dice
  75. will be rolled.</p>
  76. <p>&gt; Eg: <code class="docutils literal"><span class="pre">3D6L1</span></code> will roll three 6-sided dice, and drop the lowest, while <code class="docutils literal"><span class="pre">3D6H1</span></code> will roll three 6-sided dice, and drop the highest.</p>
  77. <p>Notes:</p>
  78. <ul class="simple">
  79. <li>If no number follow the ‘L’ or ‘H’, it is assumed to be a 1.</li>
  80. <li>‘L’ and ‘H’ can be combined inside a single pattern, but ‘L’ must precede ‘H’: <code class="docutils literal"><span class="pre">6D6L1H2</span></code></li>
  81. </ul>
  82. </div>
  83. <div class="section" id="exploding-dice">
  84. <h3>Exploding dice<a class="headerlink" href="#exploding-dice" title="Permalink to this headline">¶</a></h3>
  85. <p>Append an <code class="docutils literal"><span class="pre">X</span></code> or a <code class="docutils literal"><span class="pre">!</span></code> to a pattern to make the dice ‘explode’.
  86. ‘Explode’ means each maximal score will trigger a new roll.
  87. The resulting score will be add to the results.</p>
  88. <p>For example, if <code class="docutils literal"><span class="pre">3d6!</span></code> give <code class="docutils literal"><span class="pre">[6,3,2]</span></code>, one more die will be rolled (because 6 is the max value)
  89. The final result could be <code class="docutils literal"><span class="pre">[6,3,2,4]</span></code>.</p>
  90. </div>
  91. </div>
  92. <div class="section" id="patterns">
  93. <h2>Patterns<a class="headerlink" href="#patterns" title="Permalink to this headline">¶</a></h2>
  94. <blockquote>
  95. <div>Patterns describes here can be passed to the Pattern.parse() class
  96. method.</div></blockquote>
  97. <p><code class="docutils literal"><span class="pre">AdX</span></code> notations can be used in more complex expressions.</p>
  98. <p>Any mathematical expression is allowed:</p>
  99. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="o">&gt;&gt;</span> <span class="mi">1</span><span class="n">d10</span><span class="o">+</span><span class="mi">1</span><span class="n">d5</span><span class="o">+</span><span class="mi">1</span>
  100. <span class="o">&gt;&gt;</span> <span class="mi">1</span><span class="n">d20</span><span class="o">-</span><span class="mi">6</span>
  101. <span class="o">&gt;&gt;</span> <span class="mi">1</span><span class="n">d6</span><span class="o">*</span><span class="mi">2</span>
  102. <span class="o">&gt;&gt;</span> <span class="mi">2</span><span class="n">d20</span><span class="o">//</span><span class="mi">4</span>
  103. <span class="o">&gt;&gt;</span> <span class="mi">1</span><span class="n">d6</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span><span class="n">d4</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
  104. </pre></div>
  105. </div>
  106. <p>Following builtin python functions are also allowed: <code class="docutils literal"><span class="pre">abs</span></code>, <code class="docutils literal"><span class="pre">max</span></code>,
  107. <code class="docutils literal"><span class="pre">min</span></code>. That mean you can parse patterns like <code class="docutils literal"><span class="pre">max(1d6+1,</span> <span class="pre">2d4)</span></code>.</p>
  108. <div class="section" id="repeat">
  109. <h3>Repeat<a class="headerlink" href="#repeat" title="Permalink to this headline">¶</a></h3>
  110. <p>The <code class="docutils literal"><span class="pre">Rn(AdX)</span></code> notation can be used to roll n times the <code class="docutils literal"><span class="pre">AdX</span></code> command.</p>
  111. <p>For example, the pattern <code class="docutils literal"><span class="pre">R3(2d6+2)</span></code> will roll <code class="docutils literal"><span class="pre">2d6+2</span></code> three times: <code class="docutils literal"><span class="pre">(2d6+2)+(2d6+2)+(2d6+2)</span></code></p>
  112. </div>
  113. </div>
  114. <div class="section" id="examples">
  115. <h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
  116. <ul class="simple">
  117. <li><code class="docutils literal"><span class="pre">1d6</span></code> &gt; Roll a 6-sided die</li>
  118. <li><code class="docutils literal"><span class="pre">1d6+3</span></code> &gt; Roll a 6-sided die, then add 3</li>
  119. <li><code class="docutils literal"><span class="pre">2*(1d6+3)</span></code> &gt; Roll a 6-sided die, add 3, then multiply by 2</li>
  120. <li><code class="docutils literal"><span class="pre">3d6L2</span></code> &gt; Roll three 6-sided dice, and drop the two lowest.</li>
  121. <li><code class="docutils literal"><span class="pre">R2(1d6+3)</span></code> &gt; Similar to <code class="docutils literal"><span class="pre">1d6+3+1d6+3</span></code></li>
  122. <li><code class="docutils literal"><span class="pre">1d%</span></code> &gt; Similar to <code class="docutils literal"><span class="pre">1d100</span></code></li>
  123. <li><code class="docutils literal"><span class="pre">d6</span></code> &gt; Similar to <code class="docutils literal"><span class="pre">1d6</span></code></li>
  124. <li><code class="docutils literal"><span class="pre">min(1d6+10,3d6)</span></code> &gt; Keep the minimal score between <code class="docutils literal"><span class="pre">1d6+10</span></code> and <code class="docutils literal"><span class="pre">3d6</span></code></li>
  125. </ul>
  126. </div>
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  132. <div class="sphinxsidebarwrapper">
  133. <h1 class="logo"><a href="index.html">xdice</a></h1>
  134. <h3>Navigation</h3>
  135. <ul class="current">
  136. <li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
  137. <li class="toctree-l1 current"><a class="current reference internal" href="#">Dice Notation</a><ul>
  138. <li class="toctree-l2"><a class="reference internal" href="#dice">Dice</a><ul>
  139. <li class="toctree-l3"><a class="reference internal" href="#bases">Bases</a></li>
  140. <li class="toctree-l3"><a class="reference internal" href="#default-values">Default values</a></li>
  141. <li class="toctree-l3"><a class="reference internal" href="#d-notation">D% Notation</a></li>
  142. <li class="toctree-l3"><a class="reference internal" href="#selective-results">Selective results</a></li>
  143. <li class="toctree-l3"><a class="reference internal" href="#exploding-dice">Exploding dice</a></li>
  144. </ul>
  145. </li>
  146. <li class="toctree-l2"><a class="reference internal" href="#patterns">Patterns</a><ul>
  147. <li class="toctree-l3"><a class="reference internal" href="#repeat">Repeat</a></li>
  148. </ul>
  149. </li>
  150. <li class="toctree-l2"><a class="reference internal" href="#examples">Examples</a></li>
  151. </ul>
  152. </li>
  153. <li class="toctree-l1"><a class="reference internal" href="cli.html">Command-Line</a></li>
  154. <li class="toctree-l1"><a class="reference internal" href="api.html">API Reference</a></li>
  155. </ul>
  156. <div class="relations">
  157. <h3>Related Topics</h3>
  158. <ul>
  159. <li><a href="index.html">Documentation overview</a><ul>
  160. <li>Previous: <a href="introduction.html" title="previous chapter">Introduction</a></li>
  161. <li>Next: <a href="cli.html" title="next chapter">Command-Line</a></li>
  162. </ul></li>
  163. </ul>
  164. </div>
  165. <div id="searchbox" style="display: none" role="search">
  166. <h3>Quick search</h3>
  167. <form class="search" action="search.html" method="get">
  168. <div><input type="text" name="q" /></div>
  169. <div><input type="submit" value="Go" /></div>
  170. <input type="hidden" name="check_keywords" value="yes" />
  171. <input type="hidden" name="area" value="default" />
  172. </form>
  173. </div>
  174. <script type="text/javascript">$('#searchbox').show(0);</script>
  175. </div>
  176. </div>
  177. <div class="clearer"></div>
  178. </div>
  179. <div class="footer">
  180. &copy;2017, Olivier Massot.
  181. |
  182. Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.3</a>
  183. &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a>
  184. |
  185. <a href="_sources/dice_notation.rst.txt"
  186. rel="nofollow">Page source</a>
  187. </div>
  188. </body>
  189. </html>