rollplayerlib


Namerollplayerlib JSON
Version 0.4.0 PyPI version JSON
download
home_pageNone
SummaryA library to roll dice in a simple way, but with advanced functionality.
upload_time2024-04-13 18:45:21
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT
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/50/6f/6965412b9569252d4c3485422bcdf815acdbe8146dc782a937aef8485f79/rollplayerlib-0.4.0.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.4.0",
    "project_urls": null,
    "split_keywords": [
        "dice",
        " roll",
        " random"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "44d51f61268dd6938ca4d5b57eb95a66b88a9a698cbbeb97db15374edb35c70f",
                "md5": "d09314f4f1d162d44900829496bca44a",
                "sha256": "e3cf16f4630e1d04a5d425fcbf577357dcd26b1af3c47de5314e6608a3f130f4"
            },
            "downloads": -1,
            "filename": "rollplayerlib-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d09314f4f1d162d44900829496bca44a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9317,
            "upload_time": "2024-04-13T18:45:19",
            "upload_time_iso_8601": "2024-04-13T18:45:19.996380Z",
            "url": "https://files.pythonhosted.org/packages/44/d5/1f61268dd6938ca4d5b57eb95a66b88a9a698cbbeb97db15374edb35c70f/rollplayerlib-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "506f6965412b9569252d4c3485422bcdf815acdbe8146dc782a937aef8485f79",
                "md5": "3e82c73e0fbe5ec69ccdf762e02e09fa",
                "sha256": "d31017de4c76de08dd90ee556c181452313807ce59b3a96011a38687afbdd469"
            },
            "downloads": -1,
            "filename": "rollplayerlib-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3e82c73e0fbe5ec69ccdf762e02e09fa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9045,
            "upload_time": "2024-04-13T18:45:21",
            "upload_time_iso_8601": "2024-04-13T18:45:21.608052Z",
            "url": "https://files.pythonhosted.org/packages/50/6f/6965412b9569252d4c3485422bcdf815acdbe8146dc782a937aef8485f79/rollplayerlib-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-13 18:45:21",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "rollplayerlib"
}
        
Elapsed time: 0.30507s