Skip to main content

The swiss knife for Dice roll : Command line, API (documented!), advanced dice notation parser, compilable patterns...etc.

Project description

Build Status Coverage Status Documentation Status

xdice

xdice is a lightweight python library for managing dice, scores, and dice-notation patterns.

  • Parse almost any Dice Notation pattern: ‘1d6+1’, ‘d20’, ‘3d%’, ‘1d20//2 - 2*(6d6+2)’, ‘max(1d4+1,1d6)’, ‘3D6L2’, ‘R3(1d6+1)’…etc.

  • API help you to easily manipulate dices, patterns, and scores as objects

  • A command line tool for convenience

Python Versions

DiceRollParser has been tested with python 3.3+

Documentation

For more, see the Documentation

Examples:

import dice

# Roll simple dices with **rolldice()**

score = rolldice(6, amount=2)

# manipulates score as an integer

print(score)
>> 11
print(score * 2)
>> 22
print(score == 11)
>> True

# Or iterates over the results

for result in score:
    print(result)
>> 5
>> 6

# Parse patterns with **roll()**

ps = roll("2d6+18")

print(ps)
>> 28
print(ps.format())
>> '[5,6]+18'

ps = roll("6D%L2")

print(ps)
>> 315
print(ps.format(verbose=True))
>> '6D%L2(scores:[80, 70, 76, 89], dropped:[2, 49])'

CLI

Run python roll.py [options] <expr>

Usage:
    roll [options] <expr>

Options:
    -s               Numeric score only

    -h --help        Displays help message
    --version        Displays current xdice version

CONTRIBUTION

Any opinion / contribution is welcome, please contact us.

TO INSTALL

pip install xdice

License

xdice is under GNU License

Author

Olivier Massot, 2017, with Cro-ki Lab

Tags

dice roll d20 game random parser dices role board

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

xdice-1.1.4.tar.gz (10.8 kB view details)

Uploaded Source

File details

Details for the file xdice-1.1.4.tar.gz.

File metadata

  • Download URL: xdice-1.1.4.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for xdice-1.1.4.tar.gz
Algorithm Hash digest
SHA256 ef7022f47b5fbc9dc03048da2da29dd7a598b541d708dc1c70b4b3bdd73d6596
MD5 d35abfabeddf0ac50f0e89a823d12c61
BLAKE2b-256 bf1afdabd1072cd3cedc989991f4817174bf5dca61e0d38b8f3cab62dab5c66e

See more details on using hashes here.

Provenance

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