Poker Cards documentation

pokercards.cards – Represent cards, decks and hands

class pokercards.cards.Card(rank, suit=None)

Represents a single french-design card with it’s rank and suit.

Cards can be compared and ordered by rank. A card, relative to a card of the same rank but different suit, is compared as neither higher, lower nor equal.

Parameters:
  • rank (str) – Either the rank (one of ‘A’, ‘K’, ‘Q’, ‘J’, ‘T’, ‘9’, ... ‘2’) or rank and suit together (e.g. ‘AS’, ‘8H’, etc.)
  • suit (str) – The suit, if not given as one string with rank (one of ‘S’, ‘H’, ‘C’, ‘D’ for spade, heart, club or diamond)
Raises :

ValueError

classmethod card_list(*args)

Create a list of new cards.

Each argument should describe one card with rank and suit together.

Parameters:args – One or more cards.
Returns:List of new cards, one for each input parameter.
Return type:list of pokercards.cards.Card objects
Raises :ValueError
class pokercards.cards.Deck

Represents a single deck of 52 card.Card objects.

The deck could be imagined face down on a table. All internal lists represent the cards in order from bottom up. So dealing the top card means poping last item from the list.

pop()

Deal the top card from the deck.

Returns:pokercards.cards.Card instance
shuffle()

Shuffle the deck.

class pokercards.cards.PokerHand(cards, evaluate=True)

Compute the best hand from given cards, implementing traditional “high” poker hand ranks.

The hand object can be given more than five cards (as in Texas Hold’em or similar variants) and the evaluation will pick the best hand.

Evaluated pokercards.cards.PokerHand objects are compared and sorted by the rank of the hand.

cards

List of pokercards.cards.Card objects to make the hand from. The pokercards.cards.PokerHand.evaluate() method should be called after manual update to re-evaluate the updated hand.

Following attributes are available after evaluating the hand.

hand_rank

Readonly rank of the hand (0 = high card to 8 = straight flush)

hand_cards

Readonly list of cards which complete the rank.

kickers

Readonly list of extra cards which can break a tie.

Parameters:
evaluate()

Evaluate the rank of the hand.

Should be called either implicitly at start by leaving parameter evaluate True when creating the hand or explicitly by calling this method later, e.g. after changing the cards attribute manually.

Indices and tables

Table Of Contents

This Page