Skip to main content

Yet another dice roller for Python.

Project description

Another common RPG die rolling syntax random number generator.

Why did you do this?

That’s a very good question. I guess the answer is that I started just to see if I could, and it snowballed from there. In order to explore Python, I had built a few packages in the past that would randomly generate table top role playing game (TTRPG) characters. Each of them had a version of a dice rolling module I had written, so I had this code in a bunch of places.

“I’ll make that a package!” I thought.

But, wait, what if I want to use dice from different game systems? I had run across Backus Naur form (BNF) descriptions of languages in the past when looking into algorithms, and it seemed like writing a parser to handle different dice systems seemed a reasonable way to go. As reasonable as any thought involving, “I’ll use BNF here,” can be, I guess. And so was born Yet Another Dice Notation (YADN) and yadr.

For a description of YADN see: YADN

Do we need another Python dice rolling package?

No. Probably not. Unsurprisingly, there seems to be a lot of people who play TTRPGs and write Python packages. This is yet another one.

Hence the name.

Does it support my game?

Check through the YADN doc to see if the operations you need are described there. If not, open an issue, and I’ll see what I can do.

Why does it require Python 3.10?

Another reason for this package is I wanted a project to explore the new match case feature in Python 3.10. I’d read that parsing is one of the cases where it’s really useful.

So, I implemented it.

Then I removed it.

The problem isn’t with match case. It worked well enough, and I think the syntax was fairly clear. I’m not really sure it bought me anything over using if…elif…else, but I think that is because everything I’m lexing or parsing is fairly simple. More complex cases my see greater benefit from match…case.

The problem is with mypy. It doesn’t support match case yet. So, my options were:

  1. Ditch mypy,

  2. Mark all the match blocks as type: ignore,

  3. Go back to if.

Option 2 was just a mess in the code.

My impression is that mypy is still here to stay, so I want to try to make things work with it.

So, I went back to if, at least until mypy better supports match case.

Since I removed the match case, I can probably lower the Python requirement to 3.7 or so. If anyone ever uses this, I’ll think about it. For now, I’m only testing it under a 3.10 virtual environment, so I’ll keep it at 3.10.

How do I use this package?

If you want to execute the package from the command line, you can install the package using pip or other Python package manager, and run it as a module with the following:

python -m yadr <YADN_string>

If you want to import it into your own code, install and import the package as usual. You can then use the roll() function in the yadr module to execute a string of YADN.:

>>> import yadr
>>>
>>> yadn = '3d6'
>>> result = yadr.roll(yadn)

How do I run the tests?

I’m using the pytest library for the unit tests. To just run those tests, go to the root of your clone of the yadr repository and use the following command:

python3 -m pytest

The full suite of style checks, mypy, and such I use can be run using a shortcut I have set up in the Makefile:

make pre

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

yadr-0.1.4.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

yadr-0.1.4-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file yadr-0.1.4.tar.gz.

File metadata

  • Download URL: yadr-0.1.4.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for yadr-0.1.4.tar.gz
Algorithm Hash digest
SHA256 cf3550afff07a2f1c990ea1da68cdfa7531aa3cc475c74a32405a2fad8a77b5a
MD5 5db0f6c99040b43359fabdc6d1f50d89
BLAKE2b-256 975b55d64613f6eba583706c43b6dcec8d7e43c6b36e5c7cb8ec2453c470bd5e

See more details on using hashes here.

File details

Details for the file yadr-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: yadr-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for yadr-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ed6d1498502b047bd877527da8da4fef5e649458dd3c11969c84b1fdef670b85
MD5 1032a04c5f838cfa07faabc66cad84f8
BLAKE2b-256 a6a02fdfa20cce6bbaa98e162a2efb8b60aa922d84031097ba627bd26a53b2de

See more details on using hashes here.

Supported by

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