player module

class player.Player(name)[source]

Bases: object

A human or computer Player in a UnoGame. This holds the basic details about a player and also some functions that the UnoGame object uses to interact with the Player.

Parameters
  • name (str) – the name of the player

  • strategy (str) – “human” if the player is human or “computer” otherwise

choose_color()[source]
choose_card(top_card)[source]
get_valid_card_choices_from_hand(top_card)[source]

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

Parameters

top_card (Card) – Card at the top of the deck

Returns

(bool) for whether the card is playable

add_to_hand(card)[source]

Adds a card to a player’s hand.

Parameters

card (Card) – card to add to the player’s hand

print_hand()[source]

Prints the player’s current hand to the console

class player.HumanPlayer(name)[source]

Bases: player.Player

HummanPlayer extends the Player class. A HumanPlayer can do everything a Player can do and more: HumanPlayer gets input about choices from a user.

choose_color()[source]

Asks the player to choose a color

choose_card(top_card)[source]

Asks the player to choose a card from hand and enforces the rules of Uno

Parameters

top_card (Card) – the top card currently displayed on the deck

Returns

(Card) a valid choice of Card

class player.ComputerPlayer(name)[source]

Bases: player.Player

ComputerPlayer extends the ComputerPlayer class. AComputerPlayer can do everything a Player can do and more: ComputerPlayer uses a basic (read: bad) strategy to make choices during a game.

choose_color()[source]

Asks the player to choose a color

choose_card(top_card)[source]

Plays one turn by randomly choosing a card from hand.

Parameters
  • hand (list of Card) – the calling player’s hand

  • top_card (Card) – the top card currently displayed on the deck

Returns

(Card) a valid choice of Card

class player.RandomComputerPlayer(name)[source]

Bases: player.ComputerPlayer

RandomComputerPlayer extends the ComputerPlayer class. The RandomComputerPlayer overrides the ComputerPlayer choice functions to randomly choose a color or valid card (a much better, but still bad strategy).

choose_color()[source]

Asks the player to choose a color

choose_card(top_card)[source]

Plays one turn by randomly choosing a card from hand.

Parameters
  • hand (list of Card) – the calling player’s hand

  • top_card (Card) – the top card currently displayed on the deck

Returns

(Card) a valid choice of Card

class player.StudentComputerPlayer(name)[source]

Bases: player.ComputerPlayer

StudentComputerPlayer extends the ComputerPlayer class. Can you get your computer player to consistently win more than 30% of games?