Name | rollplayerlib JSON |
Version |
0.5.4
JSON |
| download |
home_page | None |
Summary | A library to roll dice in a simple way, but with advanced functionality. |
upload_time | 2024-08-05 00:49:20 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | MIT |
keywords |
dice
roll
random
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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:
```python
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:
```python
# 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:
```python
# 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:
```python
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.
Raw data
{
"_id": null,
"home_page": null,
"name": "rollplayerlib",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "DICE, ROLL, RANDOM",
"author": null,
"author_email": "whirlingstars <infernity@infernity.dev>",
"download_url": "https://files.pythonhosted.org/packages/93/3a/192d331b6a6421f1609ae3b5ceae76f0872385a7fce8da34272cfd77171c/rollplayerlib-0.5.4.tar.gz",
"platform": null,
"description": "\n# rollplayerlib\nThis 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.\n## Installation\nYou can install the library through pip: `pip install rollplayerlib`.\n## Usage\n### Basic Dice Roll\n\nTo roll a basic set of dice, you can use the UnifiedDice.new() method:\n\n```python\nfrom rollplayerlib import UnifiedDice, SolveMode\n\n# Roll 3 six-sided dice\ndice = UnifiedDice.new(\"3d6\")\nresult = dice.solve(SolveMode.RANDOM)\nprint(result)\n```\nThis will output something like:\n```\n\u250f\u2501\u2501\u2501\u2501 3d6 \u2501\u2501\u2501\u2501 \n\u2503 4, 2, 6\n\u2503 sum: 12\n```\n### Dice Rolls with Bonuses\n\nYou can apply bonuses to your dice rolls by using the +, -, *, and / operators:\n\n```python\n# Roll 2d6 and add 3\ndice = UnifiedDice.new(\"2d6+3\")\nresult = dice.solve(SolveMode.RANDOM)\nprint(result)\n```\n\nThis will output something like:\n```\n\u250f\u2501\u2501\u2501\u2501 2d6+3 \u2501\u2501\u2501\u2501 \n\u2503 8, 7\n\u2503 sum: 15\n```\nNote that the bonus applies to each roll individually.\n### Targeted Bonuses\n\nYou can apply targeted bonuses to specific dice in your roll using the i syntax:\n\n```python\n# Roll 45d100, multiply the 1st die by 20\ndice = UnifiedDice.new(\"45d100i1:*20\")\nresult = dice.solve(SolveMode.RANDOM)\nprint(result)\n```\nThis will output something like:\n```\n\u250f\u2501\u2501\u2501\u2501 45d100i1:*20 \u2501\u2501\u2501\u2501 \n\u2503 1080, 17, 63, 39, 47, 58, 98, 93, 16, 54, 90, 89, 99, 63, 68, 30, 26, 66, 36, 96\n\u2503 8, 85, 47, 3, 79, 5, 46, 56, 41, 41, 67, 45, 83, 44, 14, 19, 31, 96, 82, 98\n\u2503 26, 36, 39, 51, 7\n\u2503 sum: 3377\n```\n### Formatting Options\n\nYou can control the formatting of the dice roll results using the Format class:\n\n```python\nfrom rollplayerlib import UnifiedDice, SolveMode, Format, FormatType, ThresholdType\n\n# Roll 4d6, keep the highest 3 rolls\ndice = UnifiedDice.new(\"4d6\")\nformatting = Format(FormatType.FORMAT_LIST, threshold=Threshold(3, ThresholdType.GREATER))\nresult = dice.solve(SolveMode.RANDOM)\nprint(result.format(formatting))\n```\n\nThis will output something like:\n```\n\u250f\u2501\u2501\u2501\u2501 4d6 \u2501\u2501\u2501\u2501 \n\u2503 **5**, **4**, **3**, 2\n\u2503 sum: 14\n```\n## API Reference\n### `UnifiedDice`\n\n new(input_string: str) -> UnifiedDice: Constructs a UnifiedDice object from a dice roll expression.\n solve(solve_mode: SolveMode) -> RollResult: Solves the dice roll expression and returns the RollResult.\n\n### `RollResult`\n\n format(formatting: Format) -> List[tuple[str, str]]: Formats the dice roll result according to the provided Format object.\n\n### `Format`\n\n __init__(format_type: FormatType, format_args=None, threshold: Threshold=None): Constructs a Format object with the specified parameters.\n parse(expression: str) -> tuple[str, Format]: Parses a dice roll expression and returns the remaining text and the corresponding Format object.\n\n### `Threshold`\n\n __init__(limit: int, threshold_type: ThresholdType): Constructs a Threshold object with the specified limit and type.\n passing(numbers: list[int]) -> list[bool]: Checks which numbers in the provided list pass the threshold condition.\n\n### `SolveMode`\n\n RANDOM, MAX, MIN: Enum values representing different solve modes.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library to roll dice in a simple way, but with advanced functionality.",
"version": "0.5.4",
"project_urls": null,
"split_keywords": [
"dice",
" roll",
" random"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "34325bcd20dfc1a3d459bc05e8d86a06c86fc3508bdb612731d1b28a61e9abf2",
"md5": "793f7a16ab3d322de62ba56553fb7f2a",
"sha256": "25f739de5fe1a27b7011b5a881858a7c86273ece60a91a583d8ce189c8e43a56"
},
"downloads": -1,
"filename": "rollplayerlib-0.5.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "793f7a16ab3d322de62ba56553fb7f2a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 9878,
"upload_time": "2024-08-05T00:49:19",
"upload_time_iso_8601": "2024-08-05T00:49:19.719564Z",
"url": "https://files.pythonhosted.org/packages/34/32/5bcd20dfc1a3d459bc05e8d86a06c86fc3508bdb612731d1b28a61e9abf2/rollplayerlib-0.5.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "933a192d331b6a6421f1609ae3b5ceae76f0872385a7fce8da34272cfd77171c",
"md5": "2007e5a7b7680a5c9a400220b364a84c",
"sha256": "afa2e4dbeb5d1db89d368b6970a44ed4b00c7b3658097d9da7947a2b8d310c61"
},
"downloads": -1,
"filename": "rollplayerlib-0.5.4.tar.gz",
"has_sig": false,
"md5_digest": "2007e5a7b7680a5c9a400220b364a84c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9613,
"upload_time": "2024-08-05T00:49:20",
"upload_time_iso_8601": "2024-08-05T00:49:20.749292Z",
"url": "https://files.pythonhosted.org/packages/93/3a/192d331b6a6421f1609ae3b5ceae76f0872385a7fce8da34272cfd77171c/rollplayerlib-0.5.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-05 00:49:20",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "rollplayerlib"
}