Giter Site home page Giter Site logo

jpetrucciani / gamble Goto Github PK

View Code? Open in Web Editor NEW
20.0 3.0 7.0 162 KB

A python library with various gambling and gaming classes

Home Page: https://jpetrucciani.github.io/gamble/

License: MIT License

Python 95.41% Nix 4.59%
python3 gamble dice cards library playing-cards games golf hacktoberfest

gamble's Introduction

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

gamble's People

Contributors

bfly avatar cgaeta avatar cvoege avatar dependabot[bot] avatar jpetrucciani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.