Skip to main content

Deck of cards

This is a python package for building or playing card game.

Installation

This packaged was tested in Python versions 3.8, 3.9 and 3.10. to check your Python vesion,

python -V

To install deckcards,

python -m pip install deckcards

Basic usage

The deckcards modules provide a framework to implement a game of cards in python. For details on cards and games of cards check out this wikipedia page.

The two main classes are Card and Deck.

Card

An instance of Card represents a single card. Create a card object providing two parameters: rank and suit. Both string. Valid values for ranks are:

>>> import deckcards as dc
>>> print(cd.Card.ranks)
['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']

And valids values for suits are either their names or their symbols in unicode emoji representation.

Card have dictionaries to map both ways:

>>> print(dc.Card.suits)
{'club': '♣', 'diamond': '♦', 'heart': '♥', 'spade': '♠'}
>>> print(dc.Card.suits_name)
{'♣': 'club', '♦': 'diamond', '♥': 'heart', '♠': 'spade'}

A card objet is only a representation, meaning that it don't present any behavior (method). Create a card:

>>> card = dc.Card('A', '♠')
>>> print(card.rank)
A
>>> print(card.suit)
♠
>>> print(card)
A ♠
>>> card
Card.rank: A, Card.suit: ♠

By defult, 'A' is the highest rank:

>>> card.value
13

Deck

An instance of Deck has four behaviors to build most of popular card games: draw, throw, waste and pick a card, based on three main areas:

Pack: cards not in game yet. Also know as draw pile, this area feeds the other two areas.

  • Stock: cards in game. Although not implemented in this package, you can think of sub-areas of stock as players's hands and as stack (faced down cards in front of players).
  • Waste pile: cards not in game anymore.

Draw

Action of taking the card from the top of pack (draw pile) and put it in stock. Stock is where cards in game are stored. A card in game is a card in a player's hand or in table, or stack (shown of not).

Throw

Action of taking a given card from stock and throw it to wastepile. In practice the most common throw is discarding card from a player's hand.

Waste

Action of taking a given card from pack, or the card from it's top, and discard to wastepile.

Pick

Action of taking a given card from pack, or the card from it's top, and place it in stock.

A fith behavior can be reproduced with method deal(self, n_players=2, n_cards=2, standard=True) , wich returns a list of n_cards in each elements, whith length n_players. This function puts all cards in stock. The dealing fashion is standard by default, i.e., one card each hand, each round of dealing.

In src/examples is a script with black Jack implemented. You can run the game:

>> from deckcards.examples import BlackJack
>> game = BlackJack()
>> game.run()
------------
Dealer's cards: |9 ♥||? ?|      -> score: 9
player's cards: |J ♠||5 ♦|      -> score: 15
- Digit s for stand or h for hit:

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowlegments

This project used the template from https://github.com/tomchen/example_pypi_package

Metadata

Release files for deckcards 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deckcards 1.0.1
File Size Uploaded Provenance Actions
deckcards-1.0.1.tar.gz 10.4 kB Without provenance Details for deckcards-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for deckcards 1.0.1
File Interpreter ABI Platform Actions
deckcards-1.0.1-py3-none-any.whl Python 3 none any Details for deckcards-1.0.1-py3-none-any.whl

Total release size: 24.6 kB

Release files / deckcards-1.0.1.tar.gz

Download URL deckcards-1.0.1.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
460c1cd18dfbede0609a2d23db1293e25ef1fe572e680a8ee18dd033067828a6
BLAKE2b-256 checksum
How to use checksums
60cf2aa579c2d7bc28db6ac54a211e3033781830a7e86cf9aeec41d6c36290b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release files / deckcards-1.0.1-py3-none-any.whl

Download URL deckcards-1.0.1-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c975338d9cceed848e1eba1ad2ad3b92557b71f8cd46fca03b7c7b1dcab27b25
BLAKE2b-256 checksum
How to use checksums
b2a616fca399da48e2e2719f4e713ce0e91119c63099cadddd5b123c3a706c87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Security for deckcards 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page