Simple dice manipulation library allowing to compute probabilities of complex dice rolls
Project description
dice-checker
A simple library to compute probabilities with dice rolls.
Dice objects can be created from a simple RPG-like string expression:
from dice_checker import Dice
Dice("D6") # One 6 faced dice
Dice("2D8+1") # Two 8 faces dices plus 1
Dice("5D10-1D6-1") # Five 10 sided dices minus one 6 sided dice minus 1
Dice("1") # A constant value of 1
Dices can also be build from a custom map of value/probability
from dice_checker import Dice
# Using a 6 faces dice where 1 to 4 gives 0 points, a 5 gives 1 point, a 6 gives 2 points
dice = Dice({0:4, 1:1, 2:1})
And Dices can be built on the fly
from dice_checker import Dice
dice = Dice()
dice.add_event(event=1, probability=1)
dice.add_event(event=2, probability=1)
Dices have attributes:
distributionreturns a map of value/chances.expected_valuereturns the average value of the roll.
>>> from dice_checker import Dice
>>> roll = Dice("2D6+1")
>>> print(roll.distribution)
{3.0: 1.0, 4.0: 2.0, 5.0: 3.0, 6.0: 4.0, 7.0: 5.0, 8.0: 6.0, 9.0: 5.0, 10.0: 4.0, 11.0: 3.0, 12.0: 2.0, 13.0: 1.0}
>>> print(roll.expected_value)
8.0
Dices can be added and subtracted
>>> from dice_checker import Dice
>>> assert Dice("3D6") == Dice("2D6") +Dice("1D6")
>>> assert Dice("2D6-D6") == Dice("2D6") - Dice("1D6")
And Dices implement comparison operators that will return the probability of the True/False events:
>>> from dice_checker import Dice
>>> (Dice("1D10") >= Dice("1D6")).distribution
{1.0: 45.0, 0.0: 15.0}
>>> (Dice("2D6") < Dice("2D6")).distribution
{0.0: 721.0, 1.0: 575.0}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dice_checker-0.0.3.tar.gz.
File metadata
- Download URL: dice_checker-0.0.3.tar.gz
- Upload date:
- Size: 119.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
317d8e45fcf96e4849bd4cd36682fba1b608a44d192dd163eb922f94510f9335
|
|
| MD5 |
fc4a4770b53c9b3eaba3c18ef3794574
|
|
| BLAKE2b-256 |
9627299b5730f209591a833c90337b34bed568e1ed90f701bf8118173d8cfa8f
|
File details
Details for the file dice_checker-0.0.3-py3-none-any.whl.
File metadata
- Download URL: dice_checker-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0374624ee7bafa4ad7f79e3bdb91208dc247c28ec5ca94c55fd52a1ffa0795b0
|
|
| MD5 |
31bfcb5d5acfa85adb6f8ca0089f1dda
|
|
| BLAKE2b-256 |
f7f486a30b4fd9821bf908db719c12c3de3731473cf6b13f78fe10ca78a3f43b
|