game module

class game.UnoGame(human_names, computer_strategies, deck_file=None, total_turns=10)[source]

Bases: object

Creates an instance of an UnoGame which runs the logic of the game to give players turn, make sure players play valid cards, and determine when a player wins. The UnoGame also enforces the rules of special cards in Uno like reverse or draw four.

Parameters
  • deck_file (str) – The filepath to the deck of cards

  • total_rounds (int) – The number of rounds to play before ending the game

  • human_names (list of str) – names of human player (up to 4)

  • computer_strategies (list of str) – names of strategies for computer players ()

START_CARDS = 7
NUM_PLAYERS = 4
CLOCKWISE = 1
ANTICLOCKWISE = -1
COLORS = ['red', 'blue', 'green', 'yellow']
play()[source]

Plays an uno game

Returns

(str) name of the game winner

deal_starting_cards()[source]

Deals cards to all players to begin the games

play_turn()[source]

Plays one round of uno

Returns

(bool) whether the game has been won by the current player

deal_n_cards(n, player=None)[source]

Takes n cards from the Deck and deals them to a Player or returns the Card(s) if no Player is specified. If the deck is empty, the discard pile is shuffled and becomes the deck

Parameters
  • n (int) – number of cards to deal

  • player (Player) – Player to deal the card (None if no Player)

Returns

the drawn card(s)

Return type

Card or list of Card

deal_one_card(player=None)[source]

Just makes life a little easier.

Parameters

player (Player) – optional player to deal the card to

increment_player_num()[source]

Increments/decrements the current_player_index depending on the direction of the game. Resets when number drops below 0 or goes over 3.

current_player()[source]

Returns the current Player object.

next_player()[source]

Returns the next Player object depending on the direction of the game

valid_card_choice(card_choice)[source]

Check to see if the card is playable given the top card

Parameters

card_choice (Card) – a potentially playable Card

Returns

(bool) for whether the card is playable

wild()[source]

Allows the current player to change the top card color.

NOTE: this sets the color of the wild card to the players choice to maintain game state.

skip()[source]

Skips the next player’s turn

reverse()[source]

Reverses the direction of the game

special_card_action(card)[source]

Deals with a special card’s action

Parameters

card (Card) – they special card that was played

draw_two()[source]

causes the next player to draw 2 cards.

wild_draw_four()[source]

changes the top card color and makes the next player draw 4 card

game.set_up_game()[source]