Skip to main content

a collection of gambling classes/tools

Project description

PyPI version Code style: black Python 3.10+ supported

gamble is a simple library that implements a collection of some common gambling-related classes

Features

  • die, dice, d-notation
  • cards, decks, hands
  • poker ranks, hand comparison

Usage

Installation

pip install gamble

Basic Usage

Dice

import gamble

# create dice, defaults to 2 6-sided dice
dice = gamble.Dice()

# roll
dice.roll()
>>> 6
dice.rolls
>>> 1

# max, min
dice.max
>>> 12
dice.min
>>> 2

# d-notation for dice constructor
dice = gamble.Dice('d20+8')

# max, min
dice.max
>>> 28
dice.min
>>> 9

# parts
dice.parts
>>> [<d20 Die>, 8]

# roll_many
dice.roll_many(2)
>>> [8, 4]

# max_of, min_of
dice.max_of(3)
>>> (11, [7, 3, 11])
dice.min_of(3)
>>> (2, [2, 9, 4])

Cards

import gamble

# create a deck, defaults to the standard 52 card deck, no jokers
# the deck will be shuffled by default, unless you pass shuffle=False
deck = gamble.Deck()

deck.cards_left
>>> 52

deck.top
>>> <Card:7>
deck.bottom
>>> <Card:9>
deck.shuffle()  # you can also pass times=(int) to shuffle more than once

card = deck.draw()  # you can also pass times=(int) to draw a list of cards
>>> <Card:A>

# the unicode cards icons are implemented as well!
card.unicode
>>> "🂡"

# draw a poker hand, default size 5
hand = deck.draw_hand(). # you can pass size=(int) to draw a different size hand
>>> <Hand[5](straight flush) [A, 2, 3, 4, 5]>

hand.rank
>>> Rank(name='straight flush', value=8)

# arbitrary hand, from text notation
new_hand = gamble.Hand.get("2c,3c,4c,Kc,Kh")
>>> <Hand[5](pair) [2, 3, 4, K, K]>

new_hand.rank
>>> Rank(name='pair', value=1)

hand > new_hand
>>> True

Todo

  • hand equals/ge/le method
  • hand ranking when hands are very similar

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

gamble-0.12.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

gamble-0.12-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file gamble-0.12.tar.gz.

File metadata

  • Download URL: gamble-0.12.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1015-azure

File hashes

Hashes for gamble-0.12.tar.gz
Algorithm Hash digest
SHA256 85f9f7fd9bd14519cd5e9ac64a485a1eec50a6fde96b19b5cab0ab6dbdefb1cd
MD5 2eb1279f49f7f9885bb4e2c4b678ccfc
BLAKE2b-256 e097ebafd0a1eaa170f0c4bc47614eb59102bc39251e2ced1086caf2c8b453b4

See more details on using hashes here.

Provenance

File details

Details for the file gamble-0.12-py3-none-any.whl.

File metadata

  • Download URL: gamble-0.12-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1015-azure

File hashes

Hashes for gamble-0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 10c46b22cbcd6b034a2a77060a58effa9c9959874ff7625b93f28b61d4cf2562
MD5 0bfcc123f551613e0c0200150b91d82e
BLAKE2b-256 6bd46e5ba0fa43cd37b40a9fd4bee23185d818c328927d72eb8231374bfe8ff6

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