Framework for creating or playing card games
Project description
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
- Vagner Bessa - bessavagner
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for deckcards-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c975338d9cceed848e1eba1ad2ad3b92557b71f8cd46fca03b7c7b1dcab27b25 |
|
MD5 | 483ae899169be10f8ee9a4e92d60d414 |
|
BLAKE2b-256 | b2a616fca399da48e2e2719f4e713ce0e91119c63099cadddd5b123c3a706c87 |