Metadata-Version: 2.4
Name: teadice
Version: 0.1.0
Summary: A dice expression parser and evaluator with roll recording.
Author: bluefcat
License-Expression: MIT
Project-URL: Repository, https://github.com/bluefcat/DIPY
Project-URL: Issues, https://github.com/bluefcat/DIPY/issues
Keywords: dice,parser,rpg,tabletop
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Operating System :: OS Independent
Classifier: Topic :: Games/Entertainment :: Role-Playing
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyparsing<4,>=3.1.2
Provides-Extra: test
Requires-Dist: pytest<10,>=8.2; extra == "test"
Requires-Dist: pytest-asyncio<2,>=0.24; extra == "test"
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=6; extra == "dev"
Dynamic: license-file

# teadice

A Python library for parsing and evaluating dice expressions, with a record of each roll.
Requires Python 3.10 or later. Released under the MIT license.

Both the PyPI distribution name and the Python import name are **teadice**.
Import the parser with `from teadice import expression`.
The internal entry point, `from teadice.dice import expression`, is also available.

## Installation

After the first release is published on PyPI:

```console
python -m pip install teadice
```

Before publication, install from the repository root:

```console
python -m venv .venv
# Windows PowerShell
.venv\Scripts\Activate.ps1
# Linux / macOS
# source .venv/bin/activate
python -m pip install .
```

## Usage

```python
from teadice import expression, recorder

recorder.clear()
node = expression.parse_string("4d6k3", parse_all=True)[0]
result = node.evaluate()

print(list(result))         # Values of the retained dice
print(int(result))          # Total
print("\n".join(recorder))  # Roll history
```

Depending on the expression, results are integer-like (`Integer`), list-like
(`IntegerList`), or a range (`Pair`). Use `int(result)` to sum a dice result list.
The recorder holds global state; call `recorder.clear()` before starting a new
history. Concurrent evaluations require external synchronization.

| Expression | Meaning |
| --- | --- |
| `3d6`, `d6` | Roll three or one six-sided dice |
| `1d(10,20)` | Roll one integer from 10 through 20, inclusive |
| `3n2d6` | Evaluate 2d6 three times and return the total of each evaluation |
| `4d6k3` | Keep the three highest values (`K` is also accepted) |
| `4d6l2` | Keep the two lowest values (`L` is also accepted) |
| `2d6 + 3` | Arithmetic (`+`, `-`, `*`, `/`) |
| `4d6 >= 4` | Return 0 or 1 for the comparison of each die |

`/` performs floor division. Comparison operators are `>=`, `>`, `<=`, `<`,
`==`, and `!=`. Use parentheses to make the intended order of mixed arithmetic
operations explicit.
