Skip to main content

An efficient dice expression parsing tool, based on Rust and PEG grammar

Project description

OneRoll

An efficient dice expression parsing tool, based on Rust and PEG grammar.

Overview

OneRoll is a high-performance dice expression parser and roller, implemented in Rust and exposed to Python via PyO3. It supports complex dice expressions, modifiers, mathematical operations, and user comments.

Features


  • Basic dice rolling (XdY)
  • Mathematical operations: +, -, *, /, ^
  • Modifiers: !, kh, kl, dh, dl, r, ro
  • Bracket support
  • User comments (e.g., 3d6 + 2 # Attack roll)
  • Complete error handling
  • Statistical rolling and analysis
  • Rich terminal UI (TUI) via textual
  • Python SDK and CLI

Installation

pip install oneroll

Or build from source:

maturin build
pip install target/wheels/oneroll-*.whl

Usage

Python SDK Example:

   import oneroll

   # Basic roll
   result = oneroll.roll("3d6 + 2")
   print(result["total"])

   # With comment
   result = oneroll.roll("4d6kh3 # Attribute roll")
   print(result["comment"])

   # Use OneRoll class
   roller = oneroll.OneRoll()
   result = roller.roll("2d6! # Exploding dice")

Command Line Example:

python -m oneroll "3d6 + 2"
python -m oneroll --stats "3d6" --times 100

Terminal UI:

python -m oneroll.tui

Dice Expression Syntax

  • XdY: Roll X dice with Y sides
  • Modifiers: kh, kl, dh, dl, !, r, ro
  • Mathematical operations: +, -, *, /, ^
  • Comments: Add with #, e.g., 3d6 + 2 # Attack roll

Examples

# Basic
result = oneroll.roll("3d6 + 2")

# D&D attribute roll
result = oneroll.roll("4d6kh3 # Attribute")

# Statistical analysis
stats = oneroll.roll_statistics("3d6", 100)

# Comment usage
result = oneroll.roll("1d20 + 5 # Attack check")
print(result["comment"])

Documentation

License

AGPL-3.0

Authors

HsiangNianian leader@hydroroll.team

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

oneroll-1.3.2.tar.gz (96.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oneroll-1.3.2-cp39-abi3-macosx_11_0_arm64.whl (289.8 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file oneroll-1.3.2.tar.gz.

File metadata

  • Download URL: oneroll-1.3.2.tar.gz
  • Upload date:
  • Size: 96.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.6

File hashes

Hashes for oneroll-1.3.2.tar.gz
Algorithm Hash digest
SHA256 44dcf9e8898bc65bf6097040926a9a6ef9587bafad4ea03270c5ddd20a6a6a7e
MD5 0bc0d8a880b0f4212dd239110907f6fe
BLAKE2b-256 700092b816fc5c61c19c2d6659e2b7d84d56efabc1a37cddd6155e5cdc0ce321

See more details on using hashes here.

File details

Details for the file oneroll-1.3.2-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for oneroll-1.3.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0f8d82382287b3a893e81ab7403bf3194cde2f96c13bbb70215fbd5c8a2b817b
MD5 dbb2f9a59ec4e3ff4b0c50f8b17d36d3
BLAKE2b-256 cad73d82cdb4099920a1fdeaf323c64426910444d5db86efa614d7fa3a14d7e6

See more details on using hashes here.

Supported by

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