game module¶
-
class
game.UnoGame(human_names, computer_strategies, deck_file=None, total_turns=10)[source]¶ Bases:
objectCreates 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_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
-
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.
-
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.