A simple independent library for rolling dice and managing dice rolls
Project description
Call Shot to the Nuts
PyCallShot is a simple independent Python library for rolling dice and managing dice rolls in your games and applications.
Features
- Roll any number and type of dice (d4, d6, d20, d69 etc.)
- Support for complex dice mechanics:
- Advantage/disadvantage rolls
- Exploding dice
- Success thresholds and hit count a-la Shadowrun and WoD
- Dice and result modifiers
- Subtract ones (for specific game systems)
- Roll logging capability
- Reproducible results with seed support
- Save and load frequently used roll configurations
Installation
pip install pycallshot
Quick Start
import pycallshot as cs
# Create a dice tower object that holds config data, last roll, and
# provides methods for rolling, loading and saving rolls
# (optional seed for reproducibility)
tower = cs.DiceTower(seed=None, log=False)
# Simple d20 roll with 4 added to result
roll = cs.Roll._from_notation('d20+4') # 1d20+4
result = tower.roll(roll)
# Complex roll with multiple dice
complex_roll = cs.Roll(
pool=8, # Number of dice
d=6, # Six-sided dice
threshold=5, # Count successes for rolls >= 5
explode=6, # On 6s, keep result and roll again
subtractOnes=False, # Don't subtract 1s from success count
diceMod=0, # No modifier to individual dice
resultMod=0, # No modifier to final result
adv=0 # No advantage/disadvantage
)
result = tower.roll(complex_roll)
Detailed Usage
Creating Rolls
There are two ways to create a roll:
- Using the constructor:
roll = cs.Roll(
pool=3, # Number of dice
d=4, # Die sides
resultMod=4 # Add 4 to final result
)
- Using notation (similar to standard RPG notation):
roll = cs.Roll._from_notation('d20adv') # d20 with advantage
roll = cs.Roll._from_notation('2d6+4') # 2d6 plus 4
Using the Dice Tower
The DiceTower class handles the execution of rolls:
# Create a tower with logging enabled
tower = cs.DiceTower(seed=None, log=True)
# Roll the dice
result = tower.roll(roll)
# Re-roll the last roll
new_result = tower.reroll()
# Save frequently used rolls
tower.save(roll, 'attack_roll')
# List saved rolls, wait for input to select one of the rolls, and use selected roll
result = tower.from_loaded()
Roll Parameters
pool: Number of dice to rolld: Number of sides on each diethreshold: Success threshold for counting hitsexplode: Value at which dice "explode" (roll again)subtractOnes: Whether to subtract ones from success countdiceMod: Modifier added to each individual dieresultMod: Modifier added to final resultadv: Advantage (1), Disadvantage (-1), or Normal (0)
Notation
The notation string takes the following details:
dX- X-sided diceYd- the value to the left ofdis always the the number of dice to rolladv- roll with advantagedis- roll with disadvantage!X- explode values of X or highertX- success threshold Xs- subtract ones from success count+X- add X to the end result of roll-X- subtract X from the end result of roll Adding modifiers to each die is not supported in notation. Use thediceModparameter instead.
Logging
Enable logging to keep track of all rolls:
tower = cs.DiceTower(log=True)
Logs will be saved to log.txt with timestamps and detailed roll information.
Storing and Loading Rolls with CSV file
The to_csv and from_csv methods can be used to save and load rolls to and from a CSV file.
To get the headers to manually set up rolls, run to_csv once. Default path is saved_rolls.csv.
Running from_csv will overwrite the rolls currently stored in memory. Writing to_csv will overwrite existing file.
Thought about using Pandas for some fancy exporting and sorting, opted to keep independent for such a small project.
Contributing
Contributions are welcome! This is a learning project, so please feel free to make changes and submit feedback.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Authors
Dmitry Hayday
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 pycallshot-0.1.1.tar.gz.
File metadata
- Download URL: pycallshot-0.1.1.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a87e91584c38c7cc4666eacdd041636e9fc41178812d4d08f4b0fb6b0ba1ef3
|
|
| MD5 |
3e25eaaf7adcafd4c64d781df0e47301
|
|
| BLAKE2b-256 |
734935f2873b1f47696c2663bcbf9006041891513d1d524f5f8d70093711dea6
|
Provenance
The following attestation bundles were made for pycallshot-0.1.1.tar.gz:
Publisher:
publish.yml on dmitry-helios/PyCallShot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycallshot-0.1.1.tar.gz -
Subject digest:
2a87e91584c38c7cc4666eacdd041636e9fc41178812d4d08f4b0fb6b0ba1ef3 - Sigstore transparency entry: 155178089
- Sigstore integration time:
-
Permalink:
dmitry-helios/PyCallShot@0db0b2e39adca17c94c0d82f51ada88abf8e60ee -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dmitry-helios
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0db0b2e39adca17c94c0d82f51ada88abf8e60ee -
Trigger Event:
release
-
Statement type:
File details
Details for the file pycallshot-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pycallshot-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51787f885db702dd03aa2264ad88ae40406f5f7312d03b25febea1e9fadf2e7b
|
|
| MD5 |
6fd14872046c631f6ee3f5d6258c2120
|
|
| BLAKE2b-256 |
03129f7188ceb7e189e217bb8cb97817f2c0537311c1ef0a30132ce8f538818d
|
Provenance
The following attestation bundles were made for pycallshot-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on dmitry-helios/PyCallShot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycallshot-0.1.1-py3-none-any.whl -
Subject digest:
51787f885db702dd03aa2264ad88ae40406f5f7312d03b25febea1e9fadf2e7b - Sigstore transparency entry: 155178090
- Sigstore integration time:
-
Permalink:
dmitry-helios/PyCallShot@0db0b2e39adca17c94c0d82f51ada88abf8e60ee -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dmitry-helios
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0db0b2e39adca17c94c0d82f51ada88abf8e60ee -
Trigger Event:
release
-
Statement type: