Giter Club home page Giter Club logo

python-dice's Introduction

๐Ÿ‘‹ Hi! I build small Python and Rust libraries and command line tools.

python-dice's People

Contributors

borntyping avatar calebj avatar gyppo avatar harmon758 avatar nat543207 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-dice's Issues

Add inverse exploding dice

The x operator adds another dice if a threshold is passed.
Can you add the inverse? So that 1d20i = [1, 15] or 1d20i15 = [16] or [12, 19].

many thanks in advance

Add optional quantum random number generator

There are some sites with api for getting quantum random numbers, I think it'd be nice to have:
https://qrng.anu.edu.au/API/api-demo.php

They're producing random numbers by reading void fluctuations or something like this.
Anyway, these are 100% random numbers.
Some online RPG sites are already using quantum numbers.

The only problem that I can think of, this feature will need internet connection.

Tests do not pass

Hello, I am trying to make your package automatically accessible via Gentoo Linux.
The tests, however, fail with the following build.log.

To make the tests run at all, I have removed the pytest version constraint from tox.ini (the version you depend on is terribly outdated, would it be possible to bump it to a newer verision (e.g. 4.5.0)?). But the log seems to indicate issues beyond just that... I see a lot of mentions of py27, which makes me think it is confused about the interpreter version. Any ideas?

`3d6^2s` raises, `3d6^2t` doesn't total.

Noticed a slight discrepancy here, at least from user standpoint.
3d6^2t doesn't error, but it doesn't total the result either. 3d6^2s errors with AttributeError: 'Integer' object has no attribute 'sort'.

Possible solution could be to just strip t/s off the end, evaluate, then total/sort?

Error with negative rolls with modifiers

Hello! I have weird error:

dice.roll("(-1d20+4)")
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.6/site-packages/dice/init.py", line 24, in roll
return _roll(string, **kwargs)
File "/usr/lib/python3.6/site-packages/dice/init.py", line 48, in _roll
for element in elements]
File "/usr/lib/python3.6/site-packages/dice/init.py", line 48, in
for element in elements]
File "/usr/lib/python3.6/site-packages/dice/elements.py", line 65, in evaluate_cached
self.result = self.evaluate(cache=True, **kwargs)
File "/usr/lib/python3.6/site-packages/dice/elements.py", line 379, in evaluate
self.operands = self.preprocess_operands(*self.operands, **kwargs)
File "/usr/lib/python3.6/site-packages/dice/elements.py", line 415, in preprocess_operands
return [eval_wrapper(o) for o in operands]
File "/usr/lib/python3.6/site-packages/dice/elements.py", line 415, in
return [eval_wrapper(o) for o in operands]
File "/usr/lib/python3.6/site-packages/dice/elements.py", line 413, in eval_wrapper
return self.evaluate_object(operand, Integer, **kwargs)
File "/usr/lib/python3.6/site-packages/dice/elements.py", line 54, in evaluate_object
obj = cls(obj)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

However, -1d20 or 1d20+4 works. Why?

Please pin to pyparsing 2.0.1 as a minimum, not an absolute dependency

Pyparsing has updated since 2.0.1. Unless there's a reason to pin this module to a precise version of a dependency, it might be better just to identify the module at a minimum patch level?

Updating setup.py with:

    install_requires = [
        'docopt==0.6.1',
        'pyparsing>=2.0.1'
    ],

seems to work fine.

Cannot roll less than zero dice error

When I'm trying to evaluate expression (5+(-10))d10. However with -5d10 it works correctly ([-3, -2, -3, -1, -1])

  File "/usr/local/lib/python3.6/site-packages/dice/__init__.py", line 24, in roll
    return _roll(string, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/dice/__init__.py", line 58, in _roll
    raise DiceBaseException.from_other(e)
dice.exceptions.DiceFatalException: Cannot roll less than zero dice! (Add(5, -10) evaluated to -5) (at char 0), (line:1, col:1)

Make it possible to change max dices/sides

Hello, it would be useful to be able to change maximum amount of dices or sides for a selected fragment of code. I mean something like this:

roll(1000d10) # ok

setmaxdices(100)

roll(1000d10) # exception

setmaxdices(10000)

#again

or the other way to do this would be as an additional argument:

roll(expr, max_dices=10000)

I need this feature for my discord bot, sometimes changing things like this is a great way to avoid abusing commands.

Constant value is ok, but I still need dynamic changing for more flexibility, sorry if it is too much.

nvm

nvm there's raw output

Pyparsing 2.4.0 update

Pyparsing 2.4.0 broke some stuff, and it's probably a good time to go through and modernize the codebase based on it so we can keep up. See pyparsing/pyparsing#85 for the example that brought it to my attention (h/t @Harmon758).

Here's my initial idea list, which I'll probably add to over time:

  • properly use the ParseResults class returned as the tokens
  • use the builtin infixNotation facilities instead of the custom operatorPrecedence
    • needs workaround for special-casing operands like in dF and d%

In the meantime, v2.4.1 of this library has a dependency on pyparsing>=2.0.1,<2.4.0.

Multiple operation error

When you try to perfom the same operation multiple times, for example dice.roll("1+2+3") a TypeError is raised, saying op_add expected 2 arguments, got 3. It also happen with the other operators.

Callback :

`In [2]: roll("1+2+3")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-35-1de03c9290ea> in <module>()
----> 1 roll("1+2+3")

<ipython-input-5-8e8fd06e0a13> in roll(s)
      3
      4 def roll(s):
----> 5     r = _roll(s)
      6     if type(r) != int:
      7         r = sum(r)

C:\Python27\lib\site-packages\dice-1.0.0-py2.7.egg\dice\__init__.pyc in roll(string, single, verbose)
     19     if verbose:
     20         dice.elements.Element.verbose = True
---> 21     result = [element.evaluate_cached(verbose=verbose) for element in ast]
     22     if single:
     23         return dice.utilities.single(result)

C:\Python27\lib\site-packages\dice-1.0.0-py2.7.egg\dice\elements.pyc in evaluate_cached(self, verbose)
     27         """Wraps evaluate(), caching results"""
     28         if not hasattr(self, 'result'):
---> 29             self.result = self.evaluate()
     30             if self.verbose:
     31                 print("Evaluating:", str(self), "->", str(self.result))

 C:\Python27\lib\site-packages\dice-1.0.0-py2.7.egg\dice\elements.pyc in evaluate(self)
    115     def evaluate(self):
    116         self.operands = map(self.evaluate_object, self.operands)
--> 117         return self.function(*self.operands)
    118
    119     @property

TypeError: op_add expected 2 arguments, got 3

Possible to roll a negative number

I have wrapped this library using legos.dice for use in a chatbot. In my module, we merely grab the roll value and pass it straight to a call do dice.

One of my users just discovered this fun bug:

โ”‚โ€œ19:11โ€                              โคท โ•ก !roll -1d42                                                                                                                   โ”‚
โ”‚โ€œ19:11โ€                MissMoneyPenney โ•ก You Rolled: -29

verbose_print() not working on python

I can't get it to print the information I want on python. For example:

>>> import dice
>>> x = dice.roll('3d6+2d10+5')
>>> dice.utilities.verbose_print(x)
'26'

I wanted it to display something like what is displayed on the command line interface when I use the -v argument. I need the dice information so I can tell if my players crit or not.

$ roll -v 3d6+2d10+5
Result: 31
Breakdown:
Add(
  roll 3d6 -> [4, 4, 4] -> 12,
  roll 2d10 -> [4, 10] -> 14,
  5
) -> 31

Modulo operator

As used in programming languages, % would return rest from division of two numbers. I think it would be useful feature.

Add support to duplicate a result

In some RPG systems(storyteller for example), there is a chance that each played dice explodes for the same result without having to roll again.

For storyteller(in some cases):

  • For each rolled dice, if it is 10, add a 10 again.
  • For each rolled dice, if it is 1, add a 1 again.

It's a feature request, if possible, can be implemented something like this?

Possible syntax suggestions would be:

dice.roll("(10|10|10)xx10")
[10, 10, 10, 10, 10, 10]

Or a new letter:

dice.roll("(1|1|1)a1")
[1, 1, 1, 1, 1, 1]

The goal is to be able to do something like this in the end:

dice.roll("(((7d10)xx1)xx10)f8")
2

Or:

dice.roll("(((7d10)xx1)xx10)f8")
-1

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.