Documentation - petelliott/cards GitHub Wiki

cards.py

Card

Card is a simple class with no non-default methods.

creation

To create a Card:

from cards import Card

card = Card(Card.ACE,Card.SPADES)
#or
card = Card(2,Card.SPADES)

operators

card1>card2 card1<card2 card1>=card2 card1<=card2 all of these act on the numeric value of the card, ignoring suit

card1 == card2 this will check if the suit and value are the same

str(card) or print(card) this will give a string in the form "Jack of Spades"

Deck

creation

from cards import Deck

deck = Deck() #creates a new standard Deck
#or
deck = Deck(cards=array_of_cards) #creates a deck from a Card array

realShuffle()

realshuffle() tries to simulate a riffle shuffle

realShuffle() uses 3 constants:

CUT_ERROR = 10
SHUFFLE_START_ERROR = 4
SHUFFLE_ERROR = 1

CUT_ERROR: this is how far from the middle the deck it cut. 3 ±randoms are averaged for the used result.

SHUFFLE_START_ERROR: this is how many cards can be dropped initially. it is a random range.

SHUFFLE_ERROR: this is how many cards are dropped each time. a random between 1 and SHUFFLE_ERROR+1.

randShuffle()

takes all cards out of the deck and reinserts them randomly

deal()

returns the top card from the deck and removes it

addCard(card)

adds a card to the bottom of the deck

addCardMiddle(card)

splits deck into two with CUT_ERROR and inserts the card

cutDeck()

splits deck into two with CUT_ERROR and places the bottom on top

operators

len(deck) returns the number of cards

str(deck) or print(deck) prints each card one by one with a newline in between

standardDeck()

creates a standard 52 card deck in the form of an array of Cards. used in Deck