Cards Module
The cards module defines UNO cards and the deck.
Card Class
Deck Class
- class src.cards.Deck[source]
Represents a standard 108-card UNO deck.
The deck contains:
76 number cards (0-9 in each color, 0 appears once, 1-9 twice)
24 action cards (2 each of Skip, Reverse, Draw2 per color)
8 wild cards (4 Wild, 4 Wild Draw4)
- draw()
Draw the top card from the deck.
- Returns:
The drawn card
- Return type:
- Raises:
EmptyDeckError – If deck is empty
Card Constants
- src.cards.COLORS
Valid card colors:
['red', 'green', 'blue', 'yellow']
- src.cards.NUMBERS
Number card values:
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
- src.cards.ACTIONS
Action card types:
['skip', 'reverse', 'draw2']
- src.cards.WILDS
Wild card types:
['wild', 'draw4']
Example Usage
from src.cards import Card, Deck, COLORS
# Create individual cards
red_seven = Card('red', '7')
blue_skip = Card('blue', 'skip')
wild_card = Card('wild', 'wild')
# Check card properties
print(red_seven.is_number()) # True
print(blue_skip.is_special()) # True
print(wild_card.is_wild()) # True
# Check if cards match
red_five = Card('red', '5')
print(red_seven.matches(red_five)) # True (same color)
green_seven = Card('green', '7')
print(red_seven.matches(green_seven)) # True (same value)
# Create and use deck
deck = Deck()
deck.shuffle()
# Draw cards
hand = [deck.draw() for _ in range(7)]
print(f"Hand: {hand}")