Skip to main content

A handy dice roller with extended notation and arithmetic expressions management.

Project description

arithmetic-dice-roller

GitHub release (latest by date including pre-releases) PyPI Package GitHub License GitHub Pipenv locked Python version

A handy dice roller with extended notation and arithmetic expressions' management.

The package aims to provide an easy-to-use implementation of a dice roller application with multiple operators' options and automatic results calculation.

Dependencies

Syntax

Chosen syntax is inspired to the one from the CritDice mobile app (you can check the advanced notation for similarities with this package).

The output object once the expression has been evaluated ("rolled") contains:

  • the original expression
  • the expression without repeated sub-expressions
  • the expressions with evaluated dice rolls
  • the list of dice rolls (for beautifying purposes)
  • the final evaluated result
  • the optional label for the whole expression

If the package is being used as a part of another project, you can just import the Roller class and use the roll function.
A simple console script (arithmetic-dice-roller) is also provided, which requires an input with an expression and an optional label for it, separated by a space.

Every expression must not present any spaces, and can contain any number of dice rolls (big numbers and complex calculations may affect execution time), given the following format is respected:
[dice amount]d[die type][operator] where dice number can be omitted for default 1, d is case-insensitive and dice type can be any integer, f (for fudge die, case-insensitive) or % (for percentage, equal to typing in d100).
Operator can be of three different types, with only the third omitting some results (because or rerolls):

  • keeping or dropping a number of dice ([K|k|X|x][amount], any of the four combinations of keep/drop highest/lowest followed by how many needs to be kept or dropped)
  • counting successes and failures ([<=|>=][success threshold]f[<=|>=][failure threshold], any of the two comparison operators and a threshold for success/failure, with f being case-insensitive and the failure part being optional)
  • rerolling until the condition is satisfied (critics or comparison) or once ([!|R|r][|<=|>=][threshold], any of the three operators for rerolling and any of the three comparison operators, putting none means equality)

Repeating sub-expressions is also supported: these are expanded before any other parsing operations, and can be used to repeat rolls (and not multiply the result) writing the same sub-expression multiple times.
The format is [repetitions]x([sub-expression]), and the sub-expression (and all the expression in general) must have matching brackets.

The final arithmetic expression without dice notation is evaluated using SymPy, so any kind of arithmetic operation is allowed inside expressions, to provide a nice tool for complex rolls.


Feel free to suggest and submit modifications to this guide, as any kind of help is always very much appreciated and welcomed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arithmetic_dice_roller-0.3.3.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

arithmetic_dice_roller-0.3.3-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file arithmetic_dice_roller-0.3.3.tar.gz.

File metadata

File hashes

Hashes for arithmetic_dice_roller-0.3.3.tar.gz
Algorithm Hash digest
SHA256 c5309e4e86fd877ab5d09d66192ce8fe2f6d4dd38c7e6333f67b21da4ff92e81
MD5 33ff874875b4dcc89ac951888ed52f92
BLAKE2b-256 6c191b4c7e141d034e73b8d07e1b236ca2e8ec5c1b89893e18084217731bb38c

See more details on using hashes here.

File details

Details for the file arithmetic_dice_roller-0.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for arithmetic_dice_roller-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7faece7b1c6a1328503e104edd7d369650735379d3fda2a68e70bb41938000f8
MD5 0284dcc85fff10d622d61a82af3d6d9e
BLAKE2b-256 794d7fd0a91a45f4af0d5c17549a59fea96794728d5cfe76c36a4e3a578e3a2f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page