Skip to main content

A dice-rolling library for RPGs.

Project description

DiceLib

A dice-rolling library for RPGs.

Requirements

  • Python 3.5 or newer.

Installation

pip install DiceLib

Usage

>>> from DiceLib import Die
>>> # You can create custom dice by specifying the number of faces:
... d6 = Die(6)
>>> # Rolling dice is simple:
... d6.roll()
[6]
>>> d6.roll(2)
[3, 5]
>>> d6.roll(7)
[2, 2, 6, 4, 4, 3, 1]
>>> # The value returned might look like a list, and in many way acts like one,
... # but it's actually a special class called Rolls:
... roll = _
>>> type(roll)
<class 'DiceLib.rolls.Rolls'>
>>> # Rolls act like lists in many ways:
... roll
[2, 2, 6, 4, 4, 3, 1]
>>> roll[1:3]
[2, 6]
>>> roll[1:3] = [5, 5]
>>> roll
[2, 5, 5, 4, 4, 3, 1]
>>> roll[0] = 6
>>> roll
[6, 5, 5, 4, 4, 3, 1]
>>> # But in other ways, Rolls are different:
... roll.total
28
>>> roll.count
7
>>> roll.highest
6
>>> roll.lowest
1
>>> roll[2:5].highest
5
>>> roll[2:5].total
13
>>> roll < 20
False
>>> roll > 20
True
>>> roll == 28
True
>>> int(roll)
28
>>> # You can easily add or subtract from a roll:
... roll + 2
30
... roll - 8
20
>>> # You can even drop the lowest or highest rolls:
... roll.drop_lowest()
[6, 5, 5, 4, 4, 3]
>>> roll.drop_lowest(3)
[6, 5, 5, 4]
>>> roll.drop_highest()
[5, 5, 4, 4, 3, 1]
>>> roll.drop_highest(3)
[4, 4, 3, 1]
>>> # Which makes it easy, for example, to roll stats:
... stats = dict()
>>> for stat in ["str", "dex", "con", "int", "wis", "cha"]:
...     stat_roll = int(d6.roll(4).drop_lowest())
...     stats[stat] = stat_roll
...
>>> stats
{'str': 12, 'dex': 15, 'con': 14, 'int': 12, 'wis': 15, 'cha': 11}

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

DiceLib-0.2.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

DiceLib-0.2.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file DiceLib-0.2.0.tar.gz.

File metadata

  • Download URL: DiceLib-0.2.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for DiceLib-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ca782520bb21fab27753ae2b056270664327c2f77175c7bcda6700711918bd30
MD5 baf200230331a8a1f2377dedf635cbd3
BLAKE2b-256 b6b45a57b7d06933596f8bfa0a4e78019d146a1bd583752cf4ca4e45758dbd24

See more details on using hashes here.

File details

Details for the file DiceLib-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: DiceLib-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for DiceLib-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65a9cca0cb1db2d8e99e06fd61206dbfc0f79cfbca78d7d755b74ce0dd8a49eb
MD5 ee7814e9bc98c284eed485221717074d
BLAKE2b-256 29d91931401cc9c1c01e2f5cb16f4d75068caa9a3279e40a64ec67ca7b5a0879

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