Skip to main content

An Advanced and Customisable Python Playing Card Module that makes creating playing card games and running simulations general, simple and easy!

Project description

playingcards.py

An Advanced and Customisable Python Playing Card Module that makes creating playing card games and running simulations general, simple and easy!

Features

  • Easy to use python interface
  • Easy to Understand, general, Class Objects
  • Card Comparisons

Installation

Requires Python 3.9 and above

You can install the module from PyPI or by using pip.

# Linux/MacOS
pip3 install playingcards1598

# Windows
pip install playingcards1598

How To Use

Quick Start

To quickly get started you can initiate a deck

from playingcards import Deck

deck = Deck()

Shuffle the deck using shuffle()

deck.shuffle()

Draw cards from this deck by using draw_top_n()

drawn_cards = deck.draw_top_n(5)  # Draws 5 cards

print(len(deck))  # Prints 47
print(len(drawn_cards))  # Prints 5

Return the deck to original form using reset()

deck.reset()
print(len(deck))  # Prints 52

Customization

Custom Cards

This module presents three class objects for creating custom cards: Rank and Suit for the building blocks, and Card for the construction.

You can construct custom classes as follows

rank = Rank('J', num_value=11)  # Creates a Jack rank
suit = Suit('s', pretty='â™ ')  # Creates a spade suit

card = Card(rank, suit)  # Creates the Jack of Hearts

A full deck of custom cards can be created by passing it during the Deck initiation.

custom_deck = Deck([card])  # A custom deck consisting of only the card the specified above

Alternatively, a custom deck can be instantiated using the from_ranks_suits() class method

big_red_deck = Deck.from_ranks_suits(
  [Rank(value, num) for rank, num in [('A', 14), ('K', 13), ('Q', 12), ('J', 11), ('T', 10)]],
  [Suit(suit, pretty) for suit, pretty in [('h', '♥'), ('d', '♦')]]
)

Card Collections

Deck is a subclass of CardCollection

Other CardCollection's are possible. For example, to create a Texas Holdem Poker hand (two cards), you could do the following

class TexasHand(CardCollection):
    def __init__(self, cards: list[Card]):
        super().__init__(cards, maximum = 2)

Class Arguments

  • Rank Arguments

    • value str - A string representation of the value of the rank
    • num_value int (optional) - A numerical value of the card, used in games that consist of ordering
  • Suit Arguments

    • value str - The desired value of the suit - s, h, c, d for a standard deck
    • pretty str (optional) - A prettier representation of the suit - â™ , ♥, ♣, ♦ for a standard deck
  • Card Arguments

    • rank Rank - The rank of the card
    • suit Suit - The suit of the card
  • Deck and CardCollection Arguments

    • cards list - A list of the cards in the collection
    • maximum int (optional) - The maximum number of cards in the collection

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

playingcards1598-1.1.4.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file playingcards1598-1.1.4.tar.gz.

File metadata

  • Download URL: playingcards1598-1.1.4.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.0

File hashes

Hashes for playingcards1598-1.1.4.tar.gz
Algorithm Hash digest
SHA256 df0adcbb06838870f127ae7a2ba630f4f2e39cbefb206259fd81714aa0f8a0fd
MD5 099444f4bc0c6b34002afe7a976c44a8
BLAKE2b-256 17c3d76f333cbece0f823e95a68c3e14aaab3829287ce9c94f8e03d55c803567

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page