Cards Module

The cards module defines UNO cards and the deck.

Card Class

class src.cards.Card(color, value)[source]

Represents a single UNO card.

Parameters:
  • color (str) – Card color (‘red’, ‘green’, ‘blue’, ‘yellow’, ‘wild’)

  • value (str) – Card value (‘0’-‘9’, ‘skip’, ‘reverse’, ‘draw2’, ‘wild’, ‘draw4’)

color: str

The card’s color.

value: str

The card’s value/type.

is_number()

Check if this is a number card (0-9).

Returns:

True if number card

Return type:

bool

is_special()

Check if this is a special action card.

Returns:

True if skip, reverse, or draw2

Return type:

bool

is_wild()

Check if this is a wild card.

Returns:

True if wild or draw4

Return type:

bool

matches(other)

Check if this card can be played on another.

Parameters:

other (Card) – Card to compare with

Returns:

True if playable

Return type:

bool

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)

shuffle()[source]

Shuffle the deck.

draw()

Draw the top card from the deck.

Returns:

The drawn card

Return type:

Card

Raises:

EmptyDeckError – If deck is empty

add_cards(cards)

Add cards to the bottom of the deck.

Parameters:

cards (List[Card]) – Cards to add

is_empty()

Check if deck is empty.

Returns:

True if no cards remain

Return type:

bool

cards: List[Card]

The remaining cards in the deck.

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}")