Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jpetrucciani/gamble
A python library with various gambling and gaming classes
https://github.com/jpetrucciani/gamble
cards dice gamble games golf hacktoberfest library playing-cards python3
Last synced: 8 days ago
JSON representation
A python library with various gambling and gaming classes
- Host: GitHub
- URL: https://github.com/jpetrucciani/gamble
- Owner: jpetrucciani
- License: mit
- Created: 2019-08-31T16:54:18.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-08-04T16:03:56.000Z (3 months ago)
- Last Synced: 2024-10-18T23:18:26.016Z (21 days ago)
- Topics: cards, dice, gamble, games, golf, hacktoberfest, library, playing-cards, python3
- Language: Python
- Homepage: https://jpetrucciani.github.io/gamble/
- Size: 288 KB
- Stars: 21
- Watchers: 3
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![PyPI version](https://badge.fury.io/py/gamble.svg)](https://badge.fury.io/py/gamble)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![Python 3.10+ supported](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/release/python-3100/)**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
```bash
pip install gamble
```# Basic Usage
## Dice
```python
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
>>> [, 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
```python
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
>>> 52deck.top
>>>
deck.bottom
>>>
deck.shuffle() # you can also pass times=(int) to shuffle more than oncecard = deck.draw() # you can also pass times=(int) to draw a list of cards
>>># 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.rank
>>> Rank(name='straight flush', value=8)# arbitrary hand, from text notation
new_hand = gamble.Hand.get("2c,3c,4c,Kc,Kh")
>>>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