Git Product home page Git Product logo

pydealer's Introduction

PyDealer: Playing Card Package

PyDealer is a simple to use Python package for "simulating" decks of standard playing cards (also known as a French Deck). PyDealer let's you easily create Deck instances, each containing a full 52 card deck of playing cards. Each card is a separate Card instance, with a name, value, suit, and abbreviation. There is also the Stack class, which is useful for creating hands, or discard piles, etc. It is the backbone of the PyDealer package, and actually the Deck class is just a subclass of the Stack class.

PyDealer could possibly be used as part of a CLI (command line interface) card-based game, or even a graphical game as well, I suppose. It may also be of interest to beginner Python programmers, since it's a relatively simple package, which I created as a way to learn Python, packaging, testing, documentation (Sphinx), etc. I even ended up learning how to use Git a bit, which I must say was slightly frustrating at first. This package has taught me a lot, and maybe someone else can benefit from it as well. Or maybe not. Either way, here it is.

The PyDealer package can be found at the Python Package Index, and should be downloaded from there, and, ideally, installed with pip.

Note to Developers

If you want to work on this project, please make sure you are working on the latest version of the dev branch, and make your pull requests to that branch. Thanks.

Documentation

Full documentation for PyDealer can be found on readthedocs.org:

http://pydealer.readthedocs.org/en/latest/

Quick Usage Example

Here is a quick example, using IDLE, demonstrating how to construct a new Deck instance, representing a full French Deck of cards, as well as how to shuffle the deck, and deal some cards (7 of them) from it, to a hand. Then we'll print a listing of the contents of the hand, in a human readable way, with a simple print statement.

>>> import pydealer
>>> deck = pydealer.Deck()
>>> deck.shuffle()
>>> hand = deck.deal(7)
>>> hand.sort()
>>> print hand
2 of Diamonds
5 of Hearts
9 of Hearts
9 of Spades
Jack of Spades
King of Clubs
Ace of Clubs

Install/Update/Uninstall with pip

I recommend downloading and installing pip, if you haven't already, and using that to install PyDealer, from the Python Package Index.

Enter one of the following commands into your *nix Bash or Windows Command Prompt (after installing pip).

Install

$ pip install pydealer

Update

$ pip install pydealer -U

Uninstall

$ pip uninstall pydealer

Relevant Links

pydealer's People

Contributors

danielveazey avatar ikeviny avatar pokoli avatar trebek avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydealer's Issues

Name a random card (without pulling from deck)

I'm trying to simulate some magic tricks and I need a function that just names a random card without dealing it from the deck. Do you have a suggestion for the best way to do this?

A little more detail

  • create deck
  • shuffle deck
  • deal 1 card from deck
  • name and random card and see if it is the same as the dealt card (this is the function I need)

Thanks

Can't use pydealer from Python3

I have installed pydealer using pip. It works well using python2. However, when I try to use it using python3, I have the following error:
AttributeError: 'module' object has no attribute 'Deck'
>>> import pydealer
>>> dir(pydealer)
['builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', path', 'spec']

Multiple Deck options?

Any thoughts on supporting a multiple deck feature? I'm looking at doing a blackjack sort of simulator, but want to have a dealer that has done a multiple deck shuffle (e.g. double deck BJ, 6 pack, 8 pack, etc).

Thanks!

add __str__, __repr__, __hash__, and __eq__ to Card class

I saw this project /r/python, and it looks really solid. Got a small recommendation: add __str__, __repr__, __hash__, and __eq__ to the Card class. This will allow me to do this:

c = Card('Ace', 'Spades')
print(c)
c2 = Card('Ace', 'Diamonds')
print(c == c2)

I suggest something like this:

def __str__(self):
    return '%s' % (self.name)

def __repr__(self):
    return 'Card(value=%r, suit=%r)' % (self.value, self.suit)

def __hash__(self):
    return hash((self.value, self.suit))

def __eq__(self, other):
    return isinstance(other, Card) and self.value == other.value and self.suit == other.suit

I'm a big fan of implementing these 4 methods for base classes like Card because then I can use them in data structures (set, dict, etc.) without having to worry about unexpected behavior. I can also print a card and print card-related errors and get meaningful information.

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.