| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>API Reference — 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">
- var DOCUMENTATION_OPTIONS = {
- URL_ROOT: './',
- VERSION: '1.0.0',
- COLLAPSE_INDEX: false,
- FILE_SUFFIX: '.html',
- HAS_SOURCE: true,
- SOURCELINK_SUFFIX: '.txt'
- };
- </script>
- <script type="text/javascript" src="_static/jquery.js"></script>
- <script type="text/javascript" src="_static/underscore.js"></script>
- <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="prev" title="Command-Line" href="cli.html" />
-
- <link rel="stylesheet" href="_static/custom.css" type="text/css" />
-
-
- <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
- </head>
- <body>
-
- <div class="document">
- <div class="documentwrapper">
- <div class="bodywrapper">
- <div class="body" role="main">
-
- <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>
- <div class="section" id="dice-compile-pattern-string">
- <h3>dice.compile(pattern_string)<a class="headerlink" href="#dice-compile-pattern-string" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div>Similar to <cite>xdice.Pattern(pattern_string).compile()</cite></div></blockquote>
- </div>
- <div class="section" id="dice-roll-pattern-string">
- <h3>dice.roll(pattern_string)<a class="headerlink" href="#dice-roll-pattern-string" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div>Similar to <cite>xdice.Pattern(pattern_string).roll()</cite></div></blockquote>
- </div>
- <div class="section" id="dice-rolldice-faces-amount-1-drop-lowest-0-drop-highest-0">
- <h3>dice.rolldice(faces, amount=1, drop_lowest=0, drop_highest=0)<a class="headerlink" href="#dice-rolldice-faces-amount-1-drop-lowest-0-drop-highest-0" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div>Similar to <cite>xdice.Dice(faces, amount, drop_lowest, drop_highest).roll()</cite></div></blockquote>
- </div>
- </div>
- <div class="section" id="dice-class">
- <h2>Dice class<a class="headerlink" href="#dice-class" title="Permalink to this headline">¶</a></h2>
- <blockquote>
- <div>Set of dice.</div></blockquote>
- <div class="section" id="dice-init-sides-amount-1-drop-lowest-0-drop-highest-0">
- <h3>Dice.__init__ (sides, amount=1, drop_lowest=0, drop_highest=0)<a class="headerlink" href="#dice-init-sides-amount-1-drop-lowest-0-drop-highest-0" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div>Instantiate a set of dice.</div></blockquote>
- </div>
- <div class="section" id="properties">
- <h3>Properties<a class="headerlink" href="#properties" title="Permalink to this headline">¶</a></h3>
- <ul class="simple">
- <li><cite>dice.sides</cite>: number of sides of the dice</li>
- <li><cite>dice.amount</cite>: amount of dice to roll</li>
- <li><cite>dice.drop_lowest</cite>: amount of lowest scores to drop</li>
- <li><cite>dice.drop_highest</cite>: amount of highest scores to drop</li>
- <li><cite>dice.name</cite> : Descriptive name of the Dice object</li>
- </ul>
- </div>
- <div class="section" id="dice-roll">
- <h3>dice.roll()<a class="headerlink" href="#dice-roll" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div>Role the dice and return a Score object</div></blockquote>
- </div>
- <div class="section" id="classmethod-dice-parse-cls-pattern">
- <h3><em>[classmethod]</em> Dice.parse(cls, pattern)<a class="headerlink" href="#classmethod-dice-parse-cls-pattern" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div>Parse a pattern of the form ‘AdX’, where A and X are positive
- integers, then return the corresponding Dice object. Use
- ‘AdX[Ln][Hn]’ to drop the n lowest and/or highest dice when rolled.</div></blockquote>
- </div>
- </div>
- <div class="section" id="score-class">
- <h2>Score class<a class="headerlink" href="#score-class" title="Permalink to this headline">¶</a></h2>
- <blockquote>
- <div><p>Score is a subclass of integer, you can then manipulate it as you
- would do with an integer.</p>
- <div class="line-block">
- <div class="line">It also provides an access to the detailed score with the property
- ‘detail’.</div>
- <div class="line">‘detail’ is the list of the scores obtained by each dice.</div>
- </div>
- <p>Score class can also be used as an iterable, to walk trough the
- individual scores.</p>
- </div></blockquote>
- <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">eg</span><span class="p">:</span>
- <span class="o">>>></span> <span class="n">s</span> <span class="o">=</span> <span class="n">Score</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
- <span class="o">>>></span> <span class="nb">print</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
- <span class="mi">6</span>
- <span class="o">>>></span> <span class="n">s</span> <span class="o">+</span> <span class="mi">1</span>
- <span class="mi">7</span>
- <span class="o">>>></span> <span class="nb">list</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
- <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">]</span>
- </pre></div>
- </div>
- <div class="section" id="score-new-iterable-dropped-name">
- <h3>Score.__new__(iterable, dropped=[], name=’‘)<a class="headerlink" href="#score-new-iterable-dropped-name" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div><p><cite>iterable</cite> should only contain integers</p>
- <p>Score value will be the sum of the list’s values.</p>
- </div></blockquote>
- </div>
- <div class="section" id="id1">
- <h3>Properties<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
- <ul class="simple">
- <li><cite>score.detail</cite>: similar to list(score), return the list of the individual results</li>
- <li><cite>score.name</cite>: descriptive name of the dice rolled</li>
- <li><cite>score.dropped</cite>: list of the dropped results</li>
- </ul>
- </div>
- <div class="section" id="score-format-verbose-false">
- <h3>score.format(verbose=False)<a class="headerlink" href="#score-format-verbose-false" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div>A formatted string describing the detailed result.</div></blockquote>
- </div>
- </div>
- <div class="section" id="pattern-class">
- <h2>Pattern class<a class="headerlink" href="#pattern-class" title="Permalink to this headline">¶</a></h2>
- <blockquote>
- <div>Dice notation pattern.</div></blockquote>
- <div class="section" id="pattern-init-instr">
- <h3>Pattern.__init__ (instr)<a class="headerlink" href="#pattern-init-instr" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div>Instantiate a Pattern object.</div></blockquote>
- </div>
- <div class="section" id="pattern-compile">
- <h3>pattern.compile()<a class="headerlink" href="#pattern-compile" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div>Parse the pattern. Two properties are updated at this time:</div></blockquote>
- <ul>
- <li><p class="first"><em>pattern.format_string</em></p>
- <blockquote>
- <div><p>The ready-to-be-formatted string built from the <code class="docutils literal"><span class="pre">instr</span></code> argument.</p>
- <p><em>Eg: ‘1d6+4+1d4’ => ‘{0}+4-{1}’</em></p>
- </div></blockquote>
- </li>
- <li><p class="first"><em>pattern.dices</em></p>
- <blockquote>
- <div><p>The list of parsed dice.</p>
- <p><em>Eg: ‘1d6+4+1d4’ => [(Dice; sides=6;amount=1), (Dice;
- sides=4;amount=1)]</em></p>
- </div></blockquote>
- </li>
- </ul>
- </div>
- <div class="section" id="pattern-roll">
- <h3>pattern.roll()<a class="headerlink" href="#pattern-roll" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div><p>Compile the pattern if it has not been yet, then roll the dice.</p>
- <p>Return a PatternScore object.</p>
- </div></blockquote>
- </div>
- </div>
- <div class="section" id="patternscore-class">
- <h2>PatternScore class<a class="headerlink" href="#patternscore-class" title="Permalink to this headline">¶</a></h2>
- <blockquote>
- <div><p>PatternScore is a subclass of <strong>integer</strong>, you can then manipulate
- it as you would do with an integer.</p>
- <p>Moreover, you can get the list of the scores with the score(i) or
- scores() methods, and retrieve a formatted result with the format()
- method.</p>
- </div></blockquote>
- <div class="section" id="pattern-score-scores">
- <h3>pattern_score.scores()<a class="headerlink" href="#pattern-score-scores" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div>Returns the list of Score objects extracted from the pattern and
- rolled.</div></blockquote>
- </div>
- <div class="section" id="pattern-score-format-verbose-false">
- <h3>pattern_score.format(verbose=False)<a class="headerlink" href="#pattern-score-format-verbose-false" title="Permalink to this headline">¶</a></h3>
- <blockquote>
- <div>A formatted string describing the detailed result.</div></blockquote>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
- <div class="sphinxsidebarwrapper">
- <h1 class="logo"><a href="index.html">xdice</a></h1>
- <h3>Navigation</h3>
- <ul class="current">
- <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 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>
- <div class="relations">
- <h3>Related Topics</h3>
- <ul>
- <li><a href="index.html">Documentation overview</a><ul>
- <li>Previous: <a href="cli.html" title="previous chapter">Command-Line</a></li>
- </ul></li>
- </ul>
- </div>
- <div id="searchbox" style="display: none" role="search">
- <h3>Quick search</h3>
- <form class="search" action="search.html" method="get">
- <div><input type="text" name="q" /></div>
- <div><input type="submit" value="Go" /></div>
- <input type="hidden" name="check_keywords" value="yes" />
- <input type="hidden" name="area" value="default" />
- </form>
- </div>
- <script type="text/javascript">$('#searchbox').show(0);</script>
- </div>
- </div>
- <div class="clearer"></div>
- </div>
- <div class="footer">
- ©2017, Olivier Massot.
-
- |
- Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.3</a>
- & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a>
-
- |
- <a href="_sources/api.rst.txt"
- rel="nofollow">Page source</a>
- </div>
-
-
- </body>
- </html>
|