API.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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>API Reference &#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="prev" title="Command-Line" href="cli.html" />
  25. <link rel="stylesheet" href="_static/custom.css" type="text/css" />
  26. <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
  27. </head>
  28. <body>
  29. <div class="document">
  30. <div class="documentwrapper">
  31. <div class="bodywrapper">
  32. <div class="body" role="main">
  33. <div class="section" id="api-reference">
  34. <h1>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h1>
  35. <p>Import the <em>xdice</em> library with <cite>import dice</cite></p>
  36. <div class="section" id="the-dice-module">
  37. <h2>The dice module<a class="headerlink" href="#the-dice-module" title="Permalink to this headline">¶</a></h2>
  38. <div class="section" id="dice-compile-pattern-string">
  39. <h3>dice.compile(pattern_string)<a class="headerlink" href="#dice-compile-pattern-string" title="Permalink to this headline">¶</a></h3>
  40. <blockquote>
  41. <div>Similar to <cite>xdice.Pattern(pattern_string).compile()</cite></div></blockquote>
  42. </div>
  43. <div class="section" id="dice-roll-pattern-string">
  44. <h3>dice.roll(pattern_string)<a class="headerlink" href="#dice-roll-pattern-string" title="Permalink to this headline">¶</a></h3>
  45. <blockquote>
  46. <div>Similar to <cite>xdice.Pattern(pattern_string).roll()</cite></div></blockquote>
  47. </div>
  48. <div class="section" id="dice-rolldice-faces-amount-1-drop-lowest-0-drop-highest-0">
  49. <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>
  50. <blockquote>
  51. <div>Similar to <cite>xdice.Dice(faces, amount, drop_lowest, drop_highest).roll()</cite></div></blockquote>
  52. </div>
  53. </div>
  54. <div class="section" id="dice-class">
  55. <h2>Dice class<a class="headerlink" href="#dice-class" title="Permalink to this headline">¶</a></h2>
  56. <blockquote>
  57. <div>Set of dice.</div></blockquote>
  58. <div class="section" id="dice-init-sides-amount-1-drop-lowest-0-drop-highest-0">
  59. <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>
  60. <blockquote>
  61. <div>Instantiate a set of dice.</div></blockquote>
  62. </div>
  63. <div class="section" id="properties">
  64. <h3>Properties<a class="headerlink" href="#properties" title="Permalink to this headline">¶</a></h3>
  65. <ul class="simple">
  66. <li><cite>dice.sides</cite>: number of sides of the dice</li>
  67. <li><cite>dice.amount</cite>: amount of dice to roll</li>
  68. <li><cite>dice.drop_lowest</cite>: amount of lowest scores to drop</li>
  69. <li><cite>dice.drop_highest</cite>: amount of highest scores to drop</li>
  70. <li><cite>dice.name</cite> : Descriptive name of the Dice object</li>
  71. </ul>
  72. </div>
  73. <div class="section" id="dice-roll">
  74. <h3>dice.roll()<a class="headerlink" href="#dice-roll" title="Permalink to this headline">¶</a></h3>
  75. <blockquote>
  76. <div>Role the dice and return a Score object</div></blockquote>
  77. </div>
  78. <div class="section" id="classmethod-dice-parse-cls-pattern">
  79. <h3><em>[classmethod]</em> Dice.parse(cls, pattern)<a class="headerlink" href="#classmethod-dice-parse-cls-pattern" title="Permalink to this headline">¶</a></h3>
  80. <blockquote>
  81. <div>Parse a pattern of the form ‘AdX’, where A and X are positive
  82. integers, then return the corresponding Dice object. Use
  83. ‘AdX[Ln][Hn]’ to drop the n lowest and/or highest dice when rolled.</div></blockquote>
  84. </div>
  85. </div>
  86. <div class="section" id="score-class">
  87. <h2>Score class<a class="headerlink" href="#score-class" title="Permalink to this headline">¶</a></h2>
  88. <blockquote>
  89. <div><p>Score is a subclass of integer, you can then manipulate it as you
  90. would do with an integer.</p>
  91. <div class="line-block">
  92. <div class="line">It also provides an access to the detailed score with the property
  93. ‘detail’.</div>
  94. <div class="line">‘detail’ is the list of the scores obtained by each dice.</div>
  95. </div>
  96. <p>Score class can also be used as an iterable, to walk trough the
  97. individual scores.</p>
  98. </div></blockquote>
  99. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">eg</span><span class="p">:</span>
  100. <span class="o">&gt;&gt;&gt;</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>
  101. <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
  102. <span class="mi">6</span>
  103. <span class="o">&gt;&gt;&gt;</span> <span class="n">s</span> <span class="o">+</span> <span class="mi">1</span>
  104. <span class="mi">7</span>
  105. <span class="o">&gt;&gt;&gt;</span> <span class="nb">list</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
  106. <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>
  107. </pre></div>
  108. </div>
  109. <div class="section" id="score-new-iterable-dropped-name">
  110. <h3>Score.__new__(iterable, dropped=[], name=’‘)<a class="headerlink" href="#score-new-iterable-dropped-name" title="Permalink to this headline">¶</a></h3>
  111. <blockquote>
  112. <div><p><cite>iterable</cite> should only contain integers</p>
  113. <p>Score value will be the sum of the list’s values.</p>
  114. </div></blockquote>
  115. </div>
  116. <div class="section" id="id1">
  117. <h3>Properties<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
  118. <ul class="simple">
  119. <li><cite>score.detail</cite>: similar to list(score), return the list of the individual results</li>
  120. <li><cite>score.name</cite>: descriptive name of the dice rolled</li>
  121. <li><cite>score.dropped</cite>: list of the dropped results</li>
  122. </ul>
  123. </div>
  124. <div class="section" id="score-format-verbose-false">
  125. <h3>score.format(verbose=False)<a class="headerlink" href="#score-format-verbose-false" title="Permalink to this headline">¶</a></h3>
  126. <blockquote>
  127. <div>A formatted string describing the detailed result.</div></blockquote>
  128. </div>
  129. </div>
  130. <div class="section" id="pattern-class">
  131. <h2>Pattern class<a class="headerlink" href="#pattern-class" title="Permalink to this headline">¶</a></h2>
  132. <blockquote>
  133. <div>Dice notation pattern.</div></blockquote>
  134. <div class="section" id="pattern-init-instr">
  135. <h3>Pattern.__init__ (instr)<a class="headerlink" href="#pattern-init-instr" title="Permalink to this headline">¶</a></h3>
  136. <blockquote>
  137. <div>Instantiate a Pattern object.</div></blockquote>
  138. </div>
  139. <div class="section" id="pattern-compile">
  140. <h3>pattern.compile()<a class="headerlink" href="#pattern-compile" title="Permalink to this headline">¶</a></h3>
  141. <blockquote>
  142. <div>Parse the pattern. Two properties are updated at this time:</div></blockquote>
  143. <ul>
  144. <li><p class="first"><em>pattern.format_string</em></p>
  145. <blockquote>
  146. <div><p>The ready-to-be-formatted string built from the <code class="docutils literal"><span class="pre">instr</span></code> argument.</p>
  147. <p><em>Eg: ‘1d6+4+1d4’ =&gt; ‘{0}+4-{1}’</em></p>
  148. </div></blockquote>
  149. </li>
  150. <li><p class="first"><em>pattern.dices</em></p>
  151. <blockquote>
  152. <div><p>The list of parsed dice.</p>
  153. <p><em>Eg: ‘1d6+4+1d4’ =&gt; [(Dice; sides=6;amount=1), (Dice;
  154. sides=4;amount=1)]</em></p>
  155. </div></blockquote>
  156. </li>
  157. </ul>
  158. </div>
  159. <div class="section" id="pattern-roll">
  160. <h3>pattern.roll()<a class="headerlink" href="#pattern-roll" title="Permalink to this headline">¶</a></h3>
  161. <blockquote>
  162. <div><p>Compile the pattern if it has not been yet, then roll the dice.</p>
  163. <p>Return a PatternScore object.</p>
  164. </div></blockquote>
  165. </div>
  166. </div>
  167. <div class="section" id="patternscore-class">
  168. <h2>PatternScore class<a class="headerlink" href="#patternscore-class" title="Permalink to this headline">¶</a></h2>
  169. <blockquote>
  170. <div><p>PatternScore is a subclass of <strong>integer</strong>, you can then manipulate
  171. it as you would do with an integer.</p>
  172. <p>Moreover, you can get the list of the scores with the score(i) or
  173. scores() methods, and retrieve a formatted result with the format()
  174. method.</p>
  175. </div></blockquote>
  176. <div class="section" id="pattern-score-scores">
  177. <h3>pattern_score.scores()<a class="headerlink" href="#pattern-score-scores" title="Permalink to this headline">¶</a></h3>
  178. <blockquote>
  179. <div>Returns the list of Score objects extracted from the pattern and
  180. rolled.</div></blockquote>
  181. </div>
  182. <div class="section" id="pattern-score-format-verbose-false">
  183. <h3>pattern_score.format(verbose=False)<a class="headerlink" href="#pattern-score-format-verbose-false" title="Permalink to this headline">¶</a></h3>
  184. <blockquote>
  185. <div>A formatted string describing the detailed result.</div></blockquote>
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. </div>
  191. </div>
  192. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  193. <div class="sphinxsidebarwrapper">
  194. <h1 class="logo"><a href="index.html">xdice</a></h1>
  195. <h3>Navigation</h3>
  196. <ul class="current">
  197. <li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
  198. <li class="toctree-l1"><a class="reference internal" href="dice_notation.html">Dice Notation</a></li>
  199. <li class="toctree-l1"><a class="reference internal" href="cli.html">Command-Line</a></li>
  200. <li class="toctree-l1 current"><a class="current reference internal" href="#">API Reference</a><ul>
  201. <li class="toctree-l2"><a class="reference internal" href="#the-dice-module">The dice module</a><ul>
  202. <li class="toctree-l3"><a class="reference internal" href="#dice-compile-pattern-string">dice.compile(pattern_string)</a></li>
  203. <li class="toctree-l3"><a class="reference internal" href="#dice-roll-pattern-string">dice.roll(pattern_string)</a></li>
  204. <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>
  205. </ul>
  206. </li>
  207. <li class="toctree-l2"><a class="reference internal" href="#dice-class">Dice class</a><ul>
  208. <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>
  209. <li class="toctree-l3"><a class="reference internal" href="#properties">Properties</a></li>
  210. <li class="toctree-l3"><a class="reference internal" href="#dice-roll">dice.roll()</a></li>
  211. <li class="toctree-l3"><a class="reference internal" href="#classmethod-dice-parse-cls-pattern"><em>[classmethod]</em> Dice.parse(cls, pattern)</a></li>
  212. </ul>
  213. </li>
  214. <li class="toctree-l2"><a class="reference internal" href="#score-class">Score class</a><ul>
  215. <li class="toctree-l3"><a class="reference internal" href="#score-new-iterable-dropped-name">Score.__new__(iterable, dropped=[], name=’‘)</a></li>
  216. <li class="toctree-l3"><a class="reference internal" href="#id1">Properties</a></li>
  217. <li class="toctree-l3"><a class="reference internal" href="#score-format-verbose-false">score.format(verbose=False)</a></li>
  218. </ul>
  219. </li>
  220. <li class="toctree-l2"><a class="reference internal" href="#pattern-class">Pattern class</a><ul>
  221. <li class="toctree-l3"><a class="reference internal" href="#pattern-init-instr">Pattern.__init__ (instr)</a></li>
  222. <li class="toctree-l3"><a class="reference internal" href="#pattern-compile">pattern.compile()</a></li>
  223. <li class="toctree-l3"><a class="reference internal" href="#pattern-roll">pattern.roll()</a></li>
  224. </ul>
  225. </li>
  226. <li class="toctree-l2"><a class="reference internal" href="#patternscore-class">PatternScore class</a><ul>
  227. <li class="toctree-l3"><a class="reference internal" href="#pattern-score-scores">pattern_score.scores()</a></li>
  228. <li class="toctree-l3"><a class="reference internal" href="#pattern-score-format-verbose-false">pattern_score.format(verbose=False)</a></li>
  229. </ul>
  230. </li>
  231. </ul>
  232. </li>
  233. </ul>
  234. <div class="relations">
  235. <h3>Related Topics</h3>
  236. <ul>
  237. <li><a href="index.html">Documentation overview</a><ul>
  238. <li>Previous: <a href="cli.html" title="previous chapter">Command-Line</a></li>
  239. </ul></li>
  240. </ul>
  241. </div>
  242. <div id="searchbox" style="display: none" role="search">
  243. <h3>Quick search</h3>
  244. <form class="search" action="search.html" method="get">
  245. <div><input type="text" name="q" /></div>
  246. <div><input type="submit" value="Go" /></div>
  247. <input type="hidden" name="check_keywords" value="yes" />
  248. <input type="hidden" name="area" value="default" />
  249. </form>
  250. </div>
  251. <script type="text/javascript">$('#searchbox').show(0);</script>
  252. </div>
  253. </div>
  254. <div class="clearer"></div>
  255. </div>
  256. <div class="footer">
  257. &copy;2017, Olivier Massot.
  258. |
  259. Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.3</a>
  260. &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a>
  261. |
  262. <a href="_sources/api.rst.txt"
  263. rel="nofollow">Page source</a>
  264. </div>
  265. </body>
  266. </html>