Browse Source

Add dice 'explosion' (adxX or adx!)

olinox 8 years ago
parent
commit
72e6508ad2

BIN
docs/_build/doctrees/API.doctree


BIN
docs/_build/doctrees/cli.doctree


BIN
docs/_build/doctrees/dice_notation.doctree


BIN
docs/_build/doctrees/environment.pickle


BIN
docs/_build/doctrees/index.doctree


+ 34 - 9
docs/_build/html/API.html

@@ -5,7 +5,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-    <title>API &#8212; xdice 1.0.0 documentation</title>
+    <title>API Reference &#8212; xdice 1.0.0 documentation</title>
     <link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
     <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
     <script type="text/javascript">
@@ -39,8 +39,8 @@
         <div class="bodywrapper">
           <div class="body" role="main">
             
-  <div class="section" id="api">
-<h1>API<a class="headerlink" href="#api" title="Permalink to this headline">¶</a></h1>
+  <div class="section" id="api-reference">
+<h1>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h1>
 <p>Import the <em>xdice</em> library with <cite>import dice</cite></p>
 <div class="section" id="the-dice-module">
 <h2>The dice module<a class="headerlink" href="#the-dice-module" title="Permalink to this headline">¶</a></h2>
@@ -216,12 +216,37 @@ rolled.</div></blockquote>
 <li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
 <li class="toctree-l1"><a class="reference internal" href="dice_notation.html">Dice Notation</a></li>
 <li class="toctree-l1"><a class="reference internal" href="cli.html">Command-Line</a></li>
-<li class="toctree-l1 current"><a class="current reference internal" href="#">API</a><ul>
-<li class="toctree-l2"><a class="reference internal" href="#the-dice-module">The dice module</a></li>
-<li class="toctree-l2"><a class="reference internal" href="#dice-class">Dice class</a></li>
-<li class="toctree-l2"><a class="reference internal" href="#score-class">Score class</a></li>
-<li class="toctree-l2"><a class="reference internal" href="#pattern-class">Pattern class</a></li>
-<li class="toctree-l2"><a class="reference internal" href="#patternscore-class">PatternScore class</a></li>
+<li class="toctree-l1 current"><a class="current reference internal" href="#">API Reference</a><ul>
+<li class="toctree-l2"><a class="reference internal" href="#the-dice-module">The dice module</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="#dice-compile-pattern-string">dice.compile(pattern_string)</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#dice-roll-pattern-string">dice.roll(pattern_string)</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#dice-rolldice-faces-amount-1-drop-lowest-0-drop-highest-0">dice.rolldice(faces, amount=1, drop_lowest=0, drop_highest=0)</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="#dice-class">Dice class</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="#dice-init-sides-amount-1-drop-lowest-0-drop-highest-0">Dice.__init__ (sides, amount=1, drop_lowest=0, drop_highest=0)</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#properties">Properties</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#dice-roll">dice.roll()</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#classmethod-dice-parse-cls-pattern"><em>[classmethod]</em> Dice.parse(cls, pattern)</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="#score-class">Score class</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="#score-new-iterable-dropped-name">Score.__new__(iterable, dropped=[], name=’‘)</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#id1">Properties</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#score-format-verbose-false">score.format(verbose=False)</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="#pattern-class">Pattern class</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="#pattern-init-instr">Pattern.__init__ (instr)</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#pattern-compile">pattern.compile()</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#pattern-roll">pattern.roll()</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="#patternscore-class">PatternScore class</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="#pattern-score-scores">pattern_score.scores()</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#pattern-score-format-verbose-false">pattern_score.format(verbose=False)</a></li>
+</ul>
+</li>
 </ul>
 </li>
 </ul>

+ 2 - 2
docs/_build/html/_sources/api.rst.txt

@@ -1,5 +1,5 @@
-API
-===
+API Reference
+=============
 
 Import the *xdice* library with `import dice`
 

+ 12 - 6
docs/_build/html/_sources/cli.rst.txt

@@ -18,15 +18,21 @@ Run ``python roll.py [options] <expr>``
 
 -  Basic use
 
-   ``python roll 1d6+1``
-   ``>> 2       ([1]+1)``
+::
+
+   python roll 1d6+1
+   >> 2       ([1]+1)
 
 -  Numeric score only (-s)
 
-   ``python roll -s 1d6+1``
-   ``>> 2``
+::
+
+   python roll -s 1d6+1
+   >> 2
 
 -  Verbose (-v)
 
-   ``python roll -v 2*(3D6L1+2D4)+R3(1d4+2)``
-   ``>> (2*(3d6l1(scores:[5, 6], dropped:[3])+2d4(scores:[2, 1]))+(1d4(scores:[4])+2+1d4(scores:[1])+2+1d4(scores:[4])+2))``
+::
+
+   python roll -v 2*(3D6L1+2D4)+R3(1d4+2)
+   >> (2*(3d6l1(scores:[5, 6], dropped:[3])+2d4(scores:[2, 1]))+(1d4(scores:[4])+2+1d4(scores:[1])+2+1d4(scores:[4])+2))

+ 14 - 7
docs/_build/html/_sources/dice_notation.rst.txt

@@ -1,15 +1,12 @@
 Dice Notation
--------------
+=============
 
 *Dice notation* is nearly fully understood by pydice.
 
-Case sensitivity
-^^^^^^^^^^^^^^^^
-
 *xdice* is case insensitive.
 
 Dice
-~~~~
+----
 
     Patterns describes here can be passed to the Dice.parse() class
     method, and will then return the corresponding Dice object.
@@ -58,9 +55,19 @@ Notes:
 - If no number follow the ‘L’ or ‘H’, it is assumed to be a 1.
 - ‘L’ and ‘H’ can be combined inside a single pattern, but 'L' must precede 'H': ``6D6L1H2``
 
+Exploding dice
+^^^^^^^^^^^^^^
+
+Append an ``X`` or a ``!`` to a pattern to make the dice 'explode'.
+'Explode' means each maximal score will trigger a new roll.
+The resulting score will be add to the results.
+
+For example, if ``3d6!`` give ``[6,3,2]``, one more die will be rolled (because 6 is the max value)
+The final result could be ``[6,3,2,4]``.
+
 
 Patterns
-~~~~~~~~
+--------
 
     Patterns describes here can be passed to the Pattern.parse() class
     method.
@@ -91,7 +98,7 @@ For example, the pattern ``R3(2d6+2)`` will roll ``2d6+2`` three times: ``(2d6+2
 
 
 Examples
-~~~~~~~~
+--------
 
 -  ``1d6`` 				> Roll a 6-sided die
 -  ``1d6+3`` 			> Roll a 6-sided die, then add 3

+ 1 - 1
docs/_build/html/_sources/index.rst.txt

@@ -4,7 +4,7 @@ Welcome to the documentation for xdice
 Contents:
 
 .. toctree::
-    :maxdepth: 2
+    :maxdepth: 3
 
     introduction
     dice_notation

+ 23 - 16
docs/_build/html/cli.html

@@ -23,7 +23,7 @@
     <script type="text/javascript" src="_static/doctools.js"></script>
     <link rel="index" title="Index" href="genindex.html" />
     <link rel="search" title="Search" href="search.html" />
-    <link rel="next" title="API" href="api.html" />
+    <link rel="next" title="API Reference" href="api.html" />
     <link rel="prev" title="Dice Notation" href="dice_notation.html" />
    
   <link rel="stylesheet" href="_static/custom.css" type="text/css" />
@@ -54,20 +54,27 @@
     <span class="o">--</span><span class="n">version</span>        <span class="n">Displays</span> <span class="n">current</span> <span class="n">xdice</span> <span class="n">version</span>
 </pre></div>
 </div>
-<ul>
-<li><p class="first">Basic use</p>
-<p><code class="docutils literal"><span class="pre">python</span> <span class="pre">roll</span> <span class="pre">1d6+1</span></code>
-<code class="docutils literal"><span class="pre">&gt;&gt;</span> <span class="pre">2</span>&#160;&#160;&#160;&#160;&#160;&#160; <span class="pre">([1]+1)</span></code></p>
-</li>
-<li><p class="first">Numeric score only (-s)</p>
-<p><code class="docutils literal"><span class="pre">python</span> <span class="pre">roll</span> <span class="pre">-s</span> <span class="pre">1d6+1</span></code>
-<code class="docutils literal"><span class="pre">&gt;&gt;</span> <span class="pre">2</span></code></p>
-</li>
-<li><p class="first">Verbose (-v)</p>
-<p><code class="docutils literal"><span class="pre">python</span> <span class="pre">roll</span> <span class="pre">-v</span> <span class="pre">2*(3D6L1+2D4)+R3(1d4+2)</span></code>
-<code class="docutils literal"><span class="pre">&gt;&gt;</span> <span class="pre">(2*(3d6l1(scores:[5,</span> <span class="pre">6],</span> <span class="pre">dropped:[3])+2d4(scores:[2,</span> <span class="pre">1]))+(1d4(scores:[4])+2+1d4(scores:[1])+2+1d4(scores:[4])+2))</span></code></p>
-</li>
+<ul class="simple">
+<li>Basic use</li>
 </ul>
+<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">roll</span> <span class="mi">1</span><span class="n">d6</span><span class="o">+</span><span class="mi">1</span>
+<span class="o">&gt;&gt;</span> <span class="mi">2</span>       <span class="p">([</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
+</pre></div>
+</div>
+<ul class="simple">
+<li>Numeric score only (-s)</li>
+</ul>
+<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">roll</span> <span class="o">-</span><span class="n">s</span> <span class="mi">1</span><span class="n">d6</span><span class="o">+</span><span class="mi">1</span>
+<span class="o">&gt;&gt;</span> <span class="mi">2</span>
+</pre></div>
+</div>
+<ul class="simple">
+<li>Verbose (-v)</li>
+</ul>
+<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">roll</span> <span class="o">-</span><span class="n">v</span> <span class="mi">2</span><span class="o">*</span><span class="p">(</span><span class="mi">3</span><span class="n">D6L1</span><span class="o">+</span><span class="mi">2</span><span class="n">D4</span><span class="p">)</span><span class="o">+</span><span class="n">R3</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>
+<span class="o">&gt;&gt;</span> <span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="p">(</span><span class="mi">3</span><span class="n">d6l1</span><span class="p">(</span><span class="n">scores</span><span class="p">:[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="n">dropped</span><span class="p">:[</span><span class="mi">3</span><span class="p">])</span><span class="o">+</span><span class="mi">2</span><span class="n">d4</span><span class="p">(</span><span class="n">scores</span><span class="p">:[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]))</span><span class="o">+</span><span class="p">(</span><span class="mi">1</span><span class="n">d4</span><span class="p">(</span><span class="n">scores</span><span class="p">:[</span><span class="mi">4</span><span class="p">])</span><span class="o">+</span><span class="mi">2</span><span class="o">+</span><span class="mi">1</span><span class="n">d4</span><span class="p">(</span><span class="n">scores</span><span class="p">:[</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mi">2</span><span class="o">+</span><span class="mi">1</span><span class="n">d4</span><span class="p">(</span><span class="n">scores</span><span class="p">:[</span><span class="mi">4</span><span class="p">])</span><span class="o">+</span><span class="mi">2</span><span class="p">))</span>
+</pre></div>
+</div>
 </div>
 
 
@@ -90,7 +97,7 @@
 <li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
 <li class="toctree-l1"><a class="reference internal" href="dice_notation.html">Dice Notation</a></li>
 <li class="toctree-l1 current"><a class="current reference internal" href="#">Command-Line</a></li>
-<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api.html">API Reference</a></li>
 </ul>
 
 <div class="relations">
@@ -98,7 +105,7 @@
 <ul>
   <li><a href="index.html">Documentation overview</a><ul>
       <li>Previous: <a href="dice_notation.html" title="previous chapter">Dice Notation</a></li>
-      <li>Next: <a href="api.html" title="next chapter">API</a></li>
+      <li>Next: <a href="api.html" title="next chapter">API Reference</a></li>
   </ul></li>
 </ul>
 </div>

+ 34 - 22
docs/_build/html/dice_notation.html

@@ -43,19 +43,15 @@
   <div class="section" id="dice-notation">
 <h1>Dice Notation<a class="headerlink" href="#dice-notation" title="Permalink to this headline">¶</a></h1>
 <p><em>Dice notation</em> is nearly fully understood by pydice.</p>
-<div class="section" id="case-sensitivity">
-<h2>Case sensitivity<a class="headerlink" href="#case-sensitivity" title="Permalink to this headline">¶</a></h2>
 <p><em>xdice</em> is case insensitive.</p>
 <div class="section" id="dice">
-<h3>Dice<a class="headerlink" href="#dice" title="Permalink to this headline">¶</a></h3>
+<h2>Dice<a class="headerlink" href="#dice" title="Permalink to this headline">¶</a></h2>
 <blockquote>
 <div>Patterns describes here can be passed to the Dice.parse() class
 method, and will then return the corresponding Dice object.</div></blockquote>
 <p><a class="reference external" href="https://en.wikipedia.org/wiki/Dice_notation">See Wikipedia for a complete definition.</a></p>
-</div>
-</div>
 <div class="section" id="bases">
-<h2>Bases<a class="headerlink" href="#bases" title="Permalink to this headline">¶</a></h2>
+<h3>Bases<a class="headerlink" href="#bases" title="Permalink to this headline">¶</a></h3>
 <p>Die rolls are given in the form AdX. A (amount) and X (sides) are
 variables, separated by the letter “d”, which stands for die or dice.</p>
 <ul>
@@ -71,17 +67,17 @@ six-sided dice”</p>
 </ul>
 </div>
 <div class="section" id="default-values">
-<h2>Default values<a class="headerlink" href="#default-values" title="Permalink to this headline">¶</a></h2>
+<h3>Default values<a class="headerlink" href="#default-values" title="Permalink to this headline">¶</a></h3>
 <p>If the A value is omitted, it is assumed to be a 1.</p>
 <p>If the X value is omitted, it is assumed to be a 20.
 This behavior can be modified trough the class property Dice.DEFAULT_SIDES.</p>
 </div>
 <div class="section" id="d-notation">
-<h2>D% Notation<a class="headerlink" href="#d-notation" title="Permalink to this headline">¶</a></h2>
+<h3>D% Notation<a class="headerlink" href="#d-notation" title="Permalink to this headline">¶</a></h3>
 <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>
 </div>
 <div class="section" id="selective-results">
-<h2>Selective results<a class="headerlink" href="#selective-results" title="Permalink to this headline">¶</a></h2>
+<h3>Selective results<a class="headerlink" href="#selective-results" title="Permalink to this headline">¶</a></h3>
 <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’
 respectively stand for lowest and highest).</p>
 <p>In this case, the lowest/highest n scores will be discard when the dice
@@ -92,8 +88,18 @@ will be rolled.</p>
 <li>If no number follow the ‘L’ or ‘H’, it is assumed to be a 1.</li>
 <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>
 </ul>
+</div>
+<div class="section" id="exploding-dice">
+<h3>Exploding dice<a class="headerlink" href="#exploding-dice" title="Permalink to this headline">¶</a></h3>
+<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’.
+‘Explode’ means each maximal score will trigger a new roll.
+The resulting score will be add to the results.</p>
+<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)
+The final result could be <code class="docutils literal"><span class="pre">[6,3,2,4]</span></code>.</p>
+</div>
+</div>
 <div class="section" id="patterns">
-<h3>Patterns<a class="headerlink" href="#patterns" title="Permalink to this headline">¶</a></h3>
+<h2>Patterns<a class="headerlink" href="#patterns" title="Permalink to this headline">¶</a></h2>
 <blockquote>
 <div>Patterns describes here can be passed to the Pattern.parse() class
 method.</div></blockquote>
@@ -108,14 +114,14 @@ method.</div></blockquote>
 </div>
 <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>,
 <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>
-</div>
-</div>
 <div class="section" id="repeat">
-<h2>Repeat<a class="headerlink" href="#repeat" title="Permalink to this headline">¶</a></h2>
+<h3>Repeat<a class="headerlink" href="#repeat" title="Permalink to this headline">¶</a></h3>
 <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>
 <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>
+</div>
+</div>
 <div class="section" id="examples">
-<h3>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h3>
+<h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
 <ul class="simple">
 <li><code class="docutils literal"><span class="pre">1d6</span></code>                              &gt; Roll a 6-sided die</li>
 <li><code class="docutils literal"><span class="pre">1d6+3</span></code>                    &gt; Roll a 6-sided die, then add 3</li>
@@ -127,7 +133,6 @@ method.</div></blockquote>
 <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>
 </ul>
 </div>
-</div>
 </div>
 
 
@@ -149,16 +154,23 @@ method.</div></blockquote>
 <ul class="current">
 <li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
 <li class="toctree-l1 current"><a class="current reference internal" href="#">Dice Notation</a><ul>
-<li class="toctree-l2"><a class="reference internal" href="#case-sensitivity">Case sensitivity</a></li>
-<li class="toctree-l2"><a class="reference internal" href="#bases">Bases</a></li>
-<li class="toctree-l2"><a class="reference internal" href="#default-values">Default values</a></li>
-<li class="toctree-l2"><a class="reference internal" href="#d-notation">D% Notation</a></li>
-<li class="toctree-l2"><a class="reference internal" href="#selective-results">Selective results</a></li>
-<li class="toctree-l2"><a class="reference internal" href="#repeat">Repeat</a></li>
+<li class="toctree-l2"><a class="reference internal" href="#dice">Dice</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="#bases">Bases</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#default-values">Default values</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#d-notation">D% Notation</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#selective-results">Selective results</a></li>
+<li class="toctree-l3"><a class="reference internal" href="#exploding-dice">Exploding dice</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="#patterns">Patterns</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="#repeat">Repeat</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="#examples">Examples</a></li>
 </ul>
 </li>
 <li class="toctree-l1"><a class="reference internal" href="cli.html">Command-Line</a></li>
-<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api.html">API Reference</a></li>
 </ul>
 
 <div class="relations">

+ 1 - 1
docs/_build/html/genindex.html

@@ -66,7 +66,7 @@
 <li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
 <li class="toctree-l1"><a class="reference internal" href="dice_notation.html">Dice Notation</a></li>
 <li class="toctree-l1"><a class="reference internal" href="cli.html">Command-Line</a></li>
-<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api.html">API Reference</a></li>
 </ul>
 
 <div class="relations">

+ 49 - 14
docs/_build/html/index.html

@@ -46,25 +46,60 @@
 <ul>
 <li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a><ul>
 <li class="toctree-l2"><a class="reference internal" href="introduction.html#presentation">Presentation</a></li>
-<li class="toctree-l2"><a class="reference internal" href="introduction.html#what-can-it-do">What can it do?</a></li>
+<li class="toctree-l2"><a class="reference internal" href="introduction.html#what-can-it-do">What can it do?</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="introduction.html#examples">Examples</a></li>
+</ul>
+</li>
 </ul>
 </li>
 <li class="toctree-l1"><a class="reference internal" href="dice_notation.html">Dice Notation</a><ul>
-<li class="toctree-l2"><a class="reference internal" href="dice_notation.html#case-sensitivity">Case sensitivity</a></li>
-<li class="toctree-l2"><a class="reference internal" href="dice_notation.html#bases">Bases</a></li>
-<li class="toctree-l2"><a class="reference internal" href="dice_notation.html#default-values">Default values</a></li>
-<li class="toctree-l2"><a class="reference internal" href="dice_notation.html#d-notation">D% Notation</a></li>
-<li class="toctree-l2"><a class="reference internal" href="dice_notation.html#selective-results">Selective results</a></li>
-<li class="toctree-l2"><a class="reference internal" href="dice_notation.html#repeat">Repeat</a></li>
+<li class="toctree-l2"><a class="reference internal" href="dice_notation.html#dice">Dice</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="dice_notation.html#bases">Bases</a></li>
+<li class="toctree-l3"><a class="reference internal" href="dice_notation.html#default-values">Default values</a></li>
+<li class="toctree-l3"><a class="reference internal" href="dice_notation.html#d-notation">D% Notation</a></li>
+<li class="toctree-l3"><a class="reference internal" href="dice_notation.html#selective-results">Selective results</a></li>
+<li class="toctree-l3"><a class="reference internal" href="dice_notation.html#exploding-dice">Exploding dice</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="dice_notation.html#patterns">Patterns</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="dice_notation.html#repeat">Repeat</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="dice_notation.html#examples">Examples</a></li>
 </ul>
 </li>
 <li class="toctree-l1"><a class="reference internal" href="cli.html">Command-Line</a></li>
-<li class="toctree-l1"><a class="reference internal" href="api.html">API</a><ul>
-<li class="toctree-l2"><a class="reference internal" href="api.html#the-dice-module">The dice module</a></li>
-<li class="toctree-l2"><a class="reference internal" href="api.html#dice-class">Dice class</a></li>
-<li class="toctree-l2"><a class="reference internal" href="api.html#score-class">Score class</a></li>
-<li class="toctree-l2"><a class="reference internal" href="api.html#pattern-class">Pattern class</a></li>
-<li class="toctree-l2"><a class="reference internal" href="api.html#patternscore-class">PatternScore class</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api.html">API Reference</a><ul>
+<li class="toctree-l2"><a class="reference internal" href="api.html#the-dice-module">The dice module</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="api.html#dice-compile-pattern-string">dice.compile(pattern_string)</a></li>
+<li class="toctree-l3"><a class="reference internal" href="api.html#dice-roll-pattern-string">dice.roll(pattern_string)</a></li>
+<li class="toctree-l3"><a class="reference internal" href="api.html#dice-rolldice-faces-amount-1-drop-lowest-0-drop-highest-0">dice.rolldice(faces, amount=1, drop_lowest=0, drop_highest=0)</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="api.html#dice-class">Dice class</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="api.html#dice-init-sides-amount-1-drop-lowest-0-drop-highest-0">Dice.__init__ (sides, amount=1, drop_lowest=0, drop_highest=0)</a></li>
+<li class="toctree-l3"><a class="reference internal" href="api.html#properties">Properties</a></li>
+<li class="toctree-l3"><a class="reference internal" href="api.html#dice-roll">dice.roll()</a></li>
+<li class="toctree-l3"><a class="reference internal" href="api.html#classmethod-dice-parse-cls-pattern"><em>[classmethod]</em> Dice.parse(cls, pattern)</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="api.html#score-class">Score class</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="api.html#score-new-iterable-dropped-name">Score.__new__(iterable, dropped=[], name=’‘)</a></li>
+<li class="toctree-l3"><a class="reference internal" href="api.html#id1">Properties</a></li>
+<li class="toctree-l3"><a class="reference internal" href="api.html#score-format-verbose-false">score.format(verbose=False)</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="api.html#pattern-class">Pattern class</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="api.html#pattern-init-instr">Pattern.__init__ (instr)</a></li>
+<li class="toctree-l3"><a class="reference internal" href="api.html#pattern-compile">pattern.compile()</a></li>
+<li class="toctree-l3"><a class="reference internal" href="api.html#pattern-roll">pattern.roll()</a></li>
+</ul>
+</li>
+<li class="toctree-l2"><a class="reference internal" href="api.html#patternscore-class">PatternScore class</a><ul>
+<li class="toctree-l3"><a class="reference internal" href="api.html#pattern-score-scores">pattern_score.scores()</a></li>
+<li class="toctree-l3"><a class="reference internal" href="api.html#pattern-score-format-verbose-false">pattern_score.format(verbose=False)</a></li>
+</ul>
+</li>
 </ul>
 </li>
 </ul>
@@ -91,7 +126,7 @@
 <li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
 <li class="toctree-l1"><a class="reference internal" href="dice_notation.html">Dice Notation</a></li>
 <li class="toctree-l1"><a class="reference internal" href="cli.html">Command-Line</a></li>
-<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api.html">API Reference</a></li>
 </ul>
 
 <div class="relations">

BIN
docs/_build/html/objects.inv


+ 1 - 1
docs/_build/html/search.html

@@ -89,7 +89,7 @@
 <li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
 <li class="toctree-l1"><a class="reference internal" href="dice_notation.html">Dice Notation</a></li>
 <li class="toctree-l1"><a class="reference internal" href="cli.html">Command-Line</a></li>
-<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api.html">API Reference</a></li>
 </ul>
 
 <div class="relations">

File diff suppressed because it is too large
+ 0 - 0
docs/_build/html/searchindex.js


+ 10 - 0
docs/dice_notation.rst

@@ -55,6 +55,16 @@ Notes:
 - If no number follow the ‘L’ or ‘H’, it is assumed to be a 1.
 - ‘L’ and ‘H’ can be combined inside a single pattern, but 'L' must precede 'H': ``6D6L1H2``
 
+Exploding dice
+^^^^^^^^^^^^^^
+
+Append an ``X`` or a ``!`` to a pattern to make the dice 'explode'.
+'Explode' means each maximal score will trigger a new roll.
+The resulting score will be add to the results.
+
+For example, if ``3d6!`` give ``[6,3,2]``, one more die will be rolled (because 6 is the max value)
+The final result could be ``[6,3,2,4]``.
+
 
 Patterns
 --------

+ 3 - 3
roll.py

@@ -3,7 +3,7 @@ Usage:
     roll [options] <expr>
 
 Options:
-    -s               Numeric score only
+    -n               Numeric score only
     -v               Verbose result
 
     -h --help        Displays help message
@@ -28,9 +28,9 @@ if "--version" in args:
     _print_and_exit("xdice {}".format(xdice.__VERSION__))
 
 score_only = False
-if "-s" in args:
+if "-n" in args:
     score_only = True
-    args.remove("-s")
+    args.remove("-n")
 
 verbose = False
 if "-v" in args:

+ 1 - 1
setup.py

@@ -15,7 +15,7 @@ with open("README.rst") as f:
 setup(
     name='xdice',
 
-    version='1.1.3',
+    version='1.1.4',
 
     description='The swiss knife for Dice roll : Command line, API (documented!), advanced dice notation parser, compilable patterns...etc.',
     long_description=long_description,

+ 9 - 0
test.py

@@ -55,6 +55,9 @@ class Test(unittest.TestCase):
         xdice.roll("1d%")
         xdice.roll("d%")
         xdice.roll("1+R3(1d6+1)")
+        xdice.roll("3d6!")
+        xdice.roll("3d6x")
+        xdice.roll("3d6h1x")
 
         # test invalid expressions
         self.assertRaises(ValueError, xdice.roll, "")
@@ -75,6 +78,8 @@ class Test(unittest.TestCase):
         d.drop_lowest = 1
         d.drop_highest = 1
         self.assertEqual(d.__repr__(), "<Dice; sides=6; amount=6; drop_lowest=1; drop_highest=1>")
+        d.explode = True
+        self.assertEqual(d.__repr__(), "<Dice; sides=6; amount=6; drop_lowest=1; drop_highest=1; explode>")
 
         self.assertRaises(ValueError, setattr, d, "sides", -1)
         self.assertRaises(ValueError, setattr, d, "sides", "a")
@@ -100,6 +105,10 @@ class Test(unittest.TestCase):
         self.assertEqual(xdice.Dice.parse("6d1h1").roll().name, "6d1h1")
         self.assertEqual(xdice.Dice.parse("6 D 1h1").roll().name, "6d1h1")
 
+        self.assertEqual(xdice.Dice.parse("3d1!").roll(), 6)
+        self.assertEqual(xdice.Dice.parse("3d1x").roll(), 6)
+        self.assertEqual(xdice.Dice.parse("3d1lhx").roll(), 2)
+
     def test_score_object(self):
 
         s = xdice.Score([1, 2, 3])

+ 27 - 10
xdice.py

@@ -10,9 +10,6 @@ import re
 
 __VERSION__ = 1.1
 
-# TODO: (?) Dice pools, 6-sided variations, 10-sided variations,
-# Open-ended variations (https://en.wikipedia.org/wiki/Dice_notation)
-
 def compile(pattern_string):  # @ReservedAssignment
     """
     > Similar to xdice.Pattern(pattern_string).compile()
@@ -72,15 +69,16 @@ class Dice():
     Use roll() to get a Score() object.
     """
     DEFAULT_SIDES = 20
-    DICE_RE_STR = r"(?P<amount>\d*)d(?P<sides>\d*)(?:l(?P<lowest>\d*))?(?:h(?P<highest>\d*))?"
+    DICE_RE_STR = r"(?P<amount>\d*)d(?P<sides>\d*)(?:l(?P<lowest>\d*))?(?:h(?P<highest>\d*))?([x!])?"
     DICE_RE = re.compile(DICE_RE_STR)
 
-    def __init__(self, sides, amount=1, drop_lowest=0, drop_highest=0):
+    def __init__(self, sides, amount=1, drop_lowest=0, drop_highest=0, explode=False):
         """ Instantiate a Die object """
         self._sides = 1
         self._amount = 0
         self._drop_lowest = 0
         self._drop_highest = 0
+        self._explode = explode
 
         self.sides = sides
         self.amount = amount
@@ -135,19 +133,34 @@ class Dice():
             raise ValueError("You can not drop more dice than amount")
         self._drop_highest = drop_highest
 
+    @property
+    def explode(self):
+        """ Should the dice 'explode'
+        'Explode' means each maximal score will trigger a new roll.
+        The resulting score will be add to the results.
+         """
+        return self._explode
+
+    @explode.setter
+    def explode(self, explode):
+        """ Define if the dice should 'explode' """
+        self._explode = explode
+
     @property
     def name(self):
         """ build the name of the Dice """
-        return "{}d{}{}{}".format(self._amount,
+        return "{}d{}{}{}{}".format(self._amount,
                                   self._sides,
                                   "l{}".format(self._drop_lowest) if self._drop_lowest else "",
-                                  "h{}".format(self._drop_highest) if self._drop_highest else "")
+                                  "h{}".format(self._drop_highest) if self._drop_highest else "",
+                                  "x" if self._explode else "")
 
     def __repr__(self):
         """ Return a string representation of the Dice """
         lowstr = "; drop_lowest={}".format(self.drop_lowest) if self.drop_lowest else ""
         highstr = "; drop_highest={}".format(self.drop_highest) if self.drop_highest else ""
-        return "<Dice; sides={}; amount={}{}{}>".format(self.sides, self.amount, lowstr, highstr)
+        explodestr = "; explode"if self.explode else ""
+        return "<Dice; sides={}; amount={}{}{}{}>".format(self.sides, self.amount, lowstr, highstr, explodestr)
 
     def __eq__(self, d):
         """
@@ -162,6 +175,9 @@ class Dice():
         results = [random.randint(1, self._sides) for _ in range(self._amount)]
         dropped = [_pop_lowest(results) for _ in range(self._drop_lowest)] + \
                     [_pop_highest(results) for _ in range(self._drop_highest)]
+        if self._explode:
+            exploded = [random.randint(1, self._sides) for _ in range(len([score for score in results if score == self._sides]))]
+            results += exploded
         return Score(results, dropped, self.name)
 
     @classmethod
@@ -173,14 +189,15 @@ class Dice():
         if match is None:
             raise ValueError("Invalid Dice pattern ('{}')".format(pattern))
 
-        amount, sides, lowest, highest = match.groups()
+        amount, sides, lowest, highest, explode = match.groups()
 
         amount = amount or 1
         sides = sides or cls.DEFAULT_SIDES
         lowest = (lowest or 1) if lowest is not None else 0
         highest = (highest or 1) if highest is not None else 0
+        explode = bool(explode)
 
-        return Dice(*map(int, [sides, amount, lowest, highest]))
+        return Dice(*map(int, [sides, amount, lowest, highest, explode]))
 
 class Score(int):
     """ Score is a subclass of integer.

Some files were not shown because too many files changed in this diff