Welcome to Vox Cards’s documentation!

Quickstart

Install with pip

>>> py -m pip install vox_cards

Basic Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import vox_cards.deck as cards

deck = cards.Deck(2)
# Pass the number of hands to construct this deck with.

deck.deal() # The default number of cards to deal is 7

player_1, player_2 = deck.hands

for card in player_1: # Print all cards in the first hand.
    print(card.full)
    # Prints the full name of the card (i.e. "10 of Clubs").

Examples

Basic Usage Cont.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import vox_cards.deck as cards

deck = cards.Deck(2)
# Pass the number of hands to construct this deck with.

deck.deal() # The default number of cards to deal is 7

player_1, player_2 = deck.hands

for card in player_1: # Print all cards in the first hand.
    print(card.full)
    # Prints the full name of the card (i.e. "10 of Clubs").

Keep in mind that hands are iterable, but only return the cards they hold. With that in mind, there is also the ability for hands to draw and discard cards.

13
14
15
16
17
18
19
20
21
22
23
# This will draw the top 2 cards for each palyer, then discard 2 cards at random.
player_1.draw(2)
player_1.discard(2)

player_2.draw(2)
player_2.discard(2)


# You can also pass a card instance to hand.discard for discarding specific card(s).
player_1.discard(player_1.cards[0])
player_2.discard(player_2.cards[0])

Poker

This is poker… kind of. It should give you the general idea of how hands work as a “player”, and the instances created by the deck can act as the players who are playing the card game, and an AI dealer aswell. Or you could give control of the dealer hand to a player and let them be the dealer. You pick.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import vox_cards.deck as cards

deck = cards.Deck(3) # Create a deck with 3 hands

for _ in range(3):
    deck.shuffle()
    # shuffle the deck 3 times - ultra realism

player_1, player_2, river = deck.hands # create a player 1, 2, and a river out of the hands

for _ in range(2): # deal 2 cards to each player, alternating.
    player_1.draw()
    player_2.draw()

river.draw(3) # draw 3 cards on the river
river.draw() # another
river.draw() # and we have them all, lets see who won.

print("\nPlayer 1's hand:")
for card in player_1:
    print(card.full) # heres player 1's cards

print("\nPlayer 2's hand:")
for card in player_2:
    print(card.full) # and player 2's cards

print("\n\nAnd the river is:")
for card in river:
    print(card.full) # and the winner is?

Classes

Card

class vox_cards.card.Card(card_data)

A class that represents cards. Should only be created through the deck class, however inheriting from this class to add additional functionality is encouraged.

Parameters:card_data (dict) – A dictionary with a suit and value.
Returns:A card class
Return type:Card

Deck

class vox_cards.deck.Deck(hands=1, jokers=False)

A class allowing the control of hands, and storing the cards used.

Parameters:
  • hands (int) – The number of hands to construct the deck with.
  • jokers (bool) – Whether or not to construct the deck with 2 additional joker cards.
Returns:

Returns a deck object that is iterable.

Return type:

Deck

deal(amount=7)

Deals [amount] cards to all hands.

Parameters:amount (int (, optional)) – Amount of cards to deal to players, defaults to 7
shuffle(new_deck=False)

Shuffle the deck in place.

Parameters:new_deck (bool (, optional)) – Whether or nor to reset the deck back to it’s original state, removing all cards from hands, and setting drawn_cards and discarded cards back to empty lists.

Hand

class vox_cards.hand.Hand(deck)

A hand class that gives functionality to drawing, discarding, and holding cards from a deck. This class should typically not be created, but inheriting from this class to give extended functionality to a player class is encouraged. You cand replace the Deck().hands property with a list of your player classes.

Parameters:deck (Deck) – the deck that this hand belongs to
Returns:A Hand class that is iterable.
Return type:Hand
card_count

The number of cards in this hand.

Returns:The length of hand.cards
Return type:int
discard(to_discard=1)

Remove [to_discard] amount of cards fromt his hand at random and add them to hand.deck.discarded_cards list.

Parameters:to_discard (int (, optional)) – Amount of cards to discard, defaults to 1
draw(amount=1)

Simulates drawing [amount] of cards from the top of the deck, rather then getting a random card.

Parameters:amount (int (, optional)) – Number of cards to draw, defaults to 1
Returns:Returns the card(s) that were drawn.
Return type:list of Card

Suit

Note

Suit inherets from the python enum.Enum() class.

class vox_cards.card.Suit

An Enumeration to make handling card suits easier.

Parameters:suit – A number between 0 and 4 denoting the suit, they are diamonds, clubs, hearts, spades, and joker respectively.
Returns:Returns an enum representing the suit. str(Suit) returns the titlecase representation of the suit name.
Return type:enum.Enum

Overview

Indices and tables