rollplayerlib
This library provides a flexible and extensible way to handle complex dice roll expressions and formats. It supports a wide range of features, including basic dice rolls, bonuses, targeted bonuses, and various formatting options.
Installation
You can install the library through pip: pip install rollplayerlib.
Usage
Basic Dice Roll
To roll a basic set of dice, you can use the UnifiedDice.new() method:
from rollplayerlib import UnifiedDice, SolveMode
# Roll 3 six-sided dice
dice = UnifiedDice.new("3d6")
result = dice.solve(SolveMode.RANDOM)
print(result)
This will output something like:
┏━━━━ 3d6 ━━━━
┃ 4, 2, 6
┃ sum: 12
Dice Rolls with Bonuses
You can apply bonuses to your dice rolls by using the +, -, *, and / operators:
# Roll 2d6 and add 3
dice = UnifiedDice.new("2d6+3")
result = dice.solve(SolveMode.RANDOM)
print(result)
This will output something like:
┏━━━━ 2d6+3 ━━━━
┃ 8, 7
┃ sum: 15
Note that the bonus applies to each roll individually.
Targeted Bonuses
You can apply targeted bonuses to specific dice in your roll using the i syntax:
# Roll 45d100, multiply the 1st die by 20
dice = UnifiedDice.new("45d100i1:*20")
result = dice.solve(SolveMode.RANDOM)
print(result)
This will output something like:
┏━━━━ 45d100i1:*20 ━━━━
┃ 1080, 17, 63, 39, 47, 58, 98, 93, 16, 54, 90, 89, 99, 63, 68, 30, 26, 66, 36, 96
┃ 8, 85, 47, 3, 79, 5, 46, 56, 41, 41, 67, 45, 83, 44, 14, 19, 31, 96, 82, 98
┃ 26, 36, 39, 51, 7
┃ sum: 3377
Formatting Options
You can control the formatting of the dice roll results using the Format class:
from rollplayerlib import UnifiedDice, SolveMode, Format, FormatType, ThresholdType
# Roll 4d6, keep the highest 3 rolls
dice = UnifiedDice.new("4d6")
formatting = Format(FormatType.FORMAT_LIST, threshold=Threshold(3, ThresholdType.GREATER))
result = dice.solve(SolveMode.RANDOM)
print(result.format(formatting))
This will output something like:
┏━━━━ 4d6 ━━━━
┃ **5**, **4**, **3**, 2
┃ sum: 14
API Reference
UnifiedDice
new(input_string: str) -> UnifiedDice: Constructs a UnifiedDice object from a dice roll expression.
solve(solve_mode: SolveMode) -> RollResult: Solves the dice roll expression and returns the RollResult.
RollResult
format(formatting: Format) -> List[tuple[str, str]]: Formats the dice roll result according to the provided Format object.
Format
__init__(format_type: FormatType, format_args=None, threshold: Threshold=None): Constructs a Format object with the specified parameters.
parse(expression: str) -> tuple[str, Format]: Parses a dice roll expression and returns the remaining text and the corresponding Format object.
Threshold
__init__(limit: int, threshold_type: ThresholdType): Constructs a Threshold object with the specified limit and type.
passing(numbers: list[int]) -> list[bool]: Checks which numbers in the provided list pass the threshold condition.
SolveMode
RANDOM, MAX, MIN: Enum values representing different solve modes.
Metadata
Release files for rollplayerlib 0.5.11.0.0.0.0.0.0.0.0.0.0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rollplayerlib-0.5.11.0.0.0.0.0.0.0.0.0.0.0.1.tar.gz | 10.2 kB | Without provenance | Details for rollplayerlib-0.5.11.0.0.0.0.0.0.0.0.0.0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rollplayerlib-0.5.11.0.0.0.0.0.0.0.0.0.0.0.1-py3-none-any.whl | Python 3 | none | any | Details for rollplayerlib-0.5.11.0.0.0.0.0.0.0.0.0.0.0.1-py3-none-any.whl |
Total release size: 21.1 kB
Release files / rollplayerlib-0.5.11.0.0.0.0.0.0.0.0.0.0.0.1.tar.gz
| Download URL | rollplayerlib-0.5.11.0.0.0.0.0.0.0.0.0.0.0.1.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
541003a2cc5a8799a98f201aa0bf6bbfff38f68b10e599a44bc3f7e503efa666
|
|
BLAKE2b-256 checksum How to use checksums |
2b1ab87ceadd063a3db76b3064512db8508805de422e384025b0b019ac9dc155
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.2
|
Release files / rollplayerlib-0.5.11.0.0.0.0.0.0.0.0.0.0.0.1-py3-none-any.whl
| Download URL | rollplayerlib-0.5.11.0.0.0.0.0.0.0.0.0.0.0.1-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
455a901fa79ff9ec5d27f4202c517e89934675d1a767126d257ffe51b898d33c
|
|
BLAKE2b-256 checksum How to use checksums |
3890ee81767dd89ed56610a0a88ca2f13733dfb8b630265496584cca4d9bd083
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.2
|
Security for rollplayerlib 0.5.11.0.0.0.0.0.0.0.0.0.0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.