An Advanced Python Playing Card Module that makes creating playing card games simple and easy!

Overview

playingcards.py

MIT License PyPi Python Versions

An Advanced Python Playing Card Module that makes creating playing card games simple and easy!

Features

  • Easy to Understand Class Objects
  • ASCII Card Images
  • Card Comparisons
  • Duplicate Prevention within Decks
  • Optional Seed Input for Custom Generation Sequences

Installation

Requires Python 3.6 and above

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

# Linux/MacOS
pip3 install playingcards.py

# Windows
pip install playingcards.py

How To Use

This module introduces two class objects: Deck and Card.

The difference between the two classes is that the Deck class keeps track of all of the drawn cards to prevent duplicates from being generated.

Drawing Cards

The Deck class can be called with the draw_card() function to draw a card object.

Generating a card by only using the Card class happpens when you instantiate it.

Both Classes Have A Seed Argument To Modify The Random Number Generator

from playingcards import Deck, Card

# Card Generated Using Deck
player_deck = Deck()
player_card = player_deck.draw_card()

# Card Generated From Instantiation
player_card_2 = Card()

# Card Generated With A Seed
player_deck_2 = Deck(seed="abc")
player_card_3 = Card(seed="xyz")

Class Attributes

  • Deck Attributes

    • drawn_cards dict - Returns a dict of the values that were drawn from each corresponding suit.
    • cards list - Returns a list containing the class objects of each drawn card.
    • drawn int - Returns an integer of the amount of cards that have been drawn.
    • remaining int - Returns an integer amount of the remaining cards that can be drawn.
  • Card Attributes

    • deck Deck - Returns a Deck object if the card was drawn from a deck. Default: None.
    • suit int - Returns an integer that corresponds with the card's suit.
    • suit_name str - Returns a string containing the converted suit name.
    • value int - Returns an integer of the card's face value.
    • rank str|int - Returns a string if the value can be converted into a word value (Ex. 11 -> Jack). Defaults to returning an integer if its not applicable (Ex. 2 -> 2).
    • name str - Returns a string containing the full name of the card. This prints out the rank and the suit of the card. (Ex. Ace of Spades, 3 of Hearts)
    • img str - Returns a string that contains an ASCII image of the card with the corresponding suit symbol.

Class Arguments

A card object can be instantiated with preconceived values instead of using a random generator.

  • Suits are ordered numerically from 0-3.

    • 0: Spades

    • 1: Clubs

    • 2: Hearts

    • 3: Diamonds

  • Values are ordered numerically from 1-13.

    • 1: Ace

    • 2-10: Face Value

    • 11: Jack

    • 12: Queen

    • 13: King

player_card = Card(value=11, suit=1)


print(player_card)
>> Jack of Clubs

print(player_card.value)
>> 11

print(player_card.suit_name)
>> Clubs

print(player_card.rank)
>> Jack

print(player_card.img)
>> *- - -*
   ||
   |  J  |
   ||
   *- - -*

These arguments can also be used in the draw_card() function apart of the Deck class.

Card Comparisons

The card objects feature comparison features which allows their values to be compared.

When checking for equivalency, it only checks the value of the card, not the suits.

card_1 = Card(value=8, suit=0)
card_2 = Card(value=12, suit=2)
card_3 = Card(value=8, suit=3)

print(card_1 < card_2)
>> True

print(card_3 == card_1) # Returns True even if the suit is different
>> True
You might also like...
buys ethereum based on graphics card moving average price on ebay

ebay_trades buys ethereum based on graphics card moving average price on ebay Built as a meme, this application will scrape the first 3 pages of ebay

This checks that your credit card is valid or not

Credit_card_Validator This checks that your credit card is valid or not. Where is the app ? main.exe is the application to run and main.py is the file

Python Proof of Concept for retrieving Now Playing on YouTube Music with TabFS

Youtube Music TabFS Python Proof of Concept for retrieving Now Playing on YouTube Music with TabFS. music_information = get_now_playing() pprint(music

 A Advanced Powerful, Smart And Intelligent Group Management Bot With New And Powerful Features
A Advanced Powerful, Smart And Intelligent Group Management Bot With New And Powerful Features

Vegeta Robot A Advanced Powerful, Smart And Intelligent Group Management Bot With New And Powerful Features ... Written with Pyrogram and Telethon...

A Discord bot to play bluffing games like Dobbins or Bobbins

Usage: pip install -r requirements.txt python3 bot.py DISCORD_BOT_TOKEN Gameplay: All commands are case-insensitive, with trailing punctuation and spa

Decrypt PSSE layer of PSM Games (on PC)

psse-decrypt Decrypt PSSE layer of PSM Games (on PC) Works on Unity and PSM games, and meets all requirements of: https://github.com/vita-nuova/bounti

Opasium AI was specifically designed for the Opasium Games discord only. It is a bot that covers the basic functions of any other bot.

OpasiumAI Opasium AI was specifically designed for the Opasium Games discord only. It is a bot that covers the basic functions of any other bot. Insta

TgMusicBot is a telegram userbot for playing songs in telegram voice calls based on Pyrogram and PyTgCalls.

TgMusicBot [Stable] TgMusicBot is a telegram userbot for playing songs in telegram voice calls based on Pyrogram and PyTgCalls. Commands !start / !hel

Latest Open Source Code for Playing Music in Telegram Video Chat. Made with Pyrogram and Pytgcalls 💖

MusicPlayer_TG Latest Open Source Code for Playing Music in Telegram Video Chat. Made with Pyrogram and Pytgcalls 💖 Requirements 📝 FFmpeg NodeJS nod

Releases(v1.1.0)
  • v1.1.0(Mar 9, 2022)

    6 months ago when I first released this package, I've made very dumb design decisions. This release fixes those dumb decisions and adds a new class CardCollection. One of the flaws in the previous version was generating a card every time the draw_card() function instead of pre-generating cards on instantiation of the deck and drawing from there. Deck is now a child of the new CardCollection class which is made for any type of collection of cards, i.e. hand, table, bank.

    Full Changelog: https://github.com/Prodxgy/playingcards.py/compare/v1.0.1...v1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Aug 27, 2021)

    Patched an issue where draw_card() didn't have the correct parameters for a user to input their own card values/suit.

    What's Changed

    • v1.0.1 Patch by @Prodxgy in https://github.com/Prodxgy/playingcards.py/pull/5

    Full Changelog: https://github.com/Prodxgy/playingcards.py/compare/v1.0.0...v1.0.1

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Aug 27, 2021)

Owner
Blake Potvin
Blake Potvin
An advanced telegram language translator bot

Made with Python3 (C) @FayasNoushad Copyright permission under MIT License License - https://github.com/FayasNoushad/Translator-Bot-V3/blob/main/LICE

Fayas Noushad 19 Dec 24, 2022
A telegram bot help you to get stylish fonts and text

Stylish Font Bot 🐿 This is a telegram bot help you to get stylish fonts and text. Config Vars 🤖 API_HASH: Get this value from my.telegram.org. API_K

MSTL updates 1 Nov 08, 2021
Programa de código abierto para probar el API de Bitso, el exchange más importante de América Latina.

Bitso Semiautomático Programa de código abierto para probar el API de Bitso, el exchange más importante de América Latina. Desarrollador Fernando Mire

Fernando Mireles 17 Dec 07, 2022
Spacecrypto-bot - SpaceCrypto Bot Auto Clicker

SpaceCrypto Auto Clicker Bot Também fiz um para Luna Rush ( https://github.com/w

Walter Discher Cechinel 5 Feb 22, 2022
Kali Kush - Account Nuker Tool

Kali Kush - Account Nuker Tool This is a discord tool made by me, and SSL :) antho#1731 How to use? pip3 install -r requirements.txt -py kalikush.py -

ryan 3 Dec 21, 2021
Mass Instagram Checker

Mass Instagram Checker

X - MrG3P5 5 Nov 09, 2022
A small package to markdownify Notion blocks.

markdownify-notion A small package to markdownify notion blocks. Installation Install this library using pip: $ pip install markdownify-notion Usage

Sergio Sánchez Zavala 2 Oct 29, 2022
Starlink Order Status Notification

Starlink Order Status Notification This script logs into Starlink order portal, pulls your estimated delivery date and emails it to a designated email

Aaron R. 1 Jul 08, 2022
Discord Blogger Integration Using Blogger API

It's a very simple discord bot created in python using blogger api in order to search and send your website articles in your discord chat in form of an embedded message. It's pretty useful for people

Owen Singh 8 Oct 28, 2022
Track live sentiment for stocks from Reddit and Twitter and identify growing stocks

Market Sentiment About This repository can mainly be used for two things. a. Tracking the live sentiment of stocks from Reddit and Twitter b. Tracking

Market Sentiment 345 Dec 17, 2022
Advance Anonymous Sender bot with Caption Editor

AnonyMous Sender 👨‍💻 Advanced Anonymous Sender with Caption Editor Join @DaisySupport_Official 🎵 for help Features Get forwarded messages without f

Inuka Asith 13 Oct 09, 2022
A simple and stupid Miinto API wrapper

miinto-api-wrapper Miinto API Wrapper is a simple python wrapper for Miinto API. Miinto is a fashion luxury marketplace. For more information see the

Giuseppe Checchia 3 Jan 09, 2022
OGE-2022-na-Python - Solving problems in python for the OGE 2022

OGE-2022-na-Python Решение задачек на питоне для ОГЭ 2022 Тут разобраны разные в

Slava 0 Oct 14, 2022
Mailjet API implementation in Python

READ THIS FIRST!! This repository isn't compatible with the current Mailjet API (v3) and, as a consequence, is considered deprecated and won't undergo

Rick van Hattem 18 Oct 21, 2022
all-in-one wrapper for NASA API's

=========== About bowshock is an all-in-one wrapper for NASA API's. Here is a list of currently supported API's : NASA Earth API NASA APOD (Astronomy

Emir Ozer 85 Nov 09, 2022
AWS DeepRacer Free Student Workshop: Run faster by using your custom waypoints

AWS DeepRacer Free Student Workshop: Run faster by using your custom waypoints Reward Function Template for waypoints def reward_function(params):

Yuen Cheuk Lam 88 Nov 27, 2022
Joshua McDonagh 1 Jan 24, 2022
The most expensive version of Conway's Game of Life - running on the Ethereum Blockchain

GameOfLife The most expensive implementation of Conway's Game of Life ever - over $2,000 per step! (Probably the slowest too!) Conway's Game of Life r

75 Nov 26, 2022
This tool is created by Shahzain and is one of the best self bots out there!

Shahzain SelfBot This tool is created by Shahzain and is one of the best self bots out there! Features Token Destroyer! Server Nuker(50-100 Bans Per S

Shahzain 6 Apr 02, 2022
471 Dec 24, 2022