Skip to content
/ uno Public
forked from bennuttall/uno

Python (re-)implementation of the card game Uno using DoublyLinkedCircularLists (in this case, DoublyLinkedCircularPlayerLists).

Notifications You must be signed in to change notification settings

imatheussm/uno

 
 

Repository files navigation

Uno (with doubly-linked circular lists)

An adaptation of the original implementation (located under references) which uses the DoublyLinkedCircularPlayerList class I created (along with an adapted UnoPlayer class with previous and next pointers) instead of the ReversibleCycle class originally employed.

Original project

https://github.com/bennuttall/uno

Rules

https://en.wikipedia.org/wiki/Uno_(card_game)#Official_rules

Usage

An example auto-generated game of 5 players:

from uno import UnoGame, COLORS
import random

game = UnoGame(5)

while game.is_active:
    player = game.current_player
    player_id = player.player_id
    if player.can_play(game.current_card):
        for i, card in enumerate(player.hand):
            if game.current_card.playable(card):
                if card.color == 'black':
                    new_color = random.choice(COLORS)
                else:
                    new_color = None
                print("Player {} played {}".format(player, card))
                game.play(player=player_id, card=i, new_color=new_color)
                break
    else:
        print("Player {} picked up".format(player))
        game.play(player=player_id, card=None)

See random_game.py, which contains a similar version (with a random number of players to each match).

AI

A simple interactive AI version of the game can be played using keyboard inputs. Just create an instance of AIUnoGame with the required number of players:

from uno import AIUnoGame

game = AIUnoGame(5)

You will be assigned a player number at random, and will be asked to make your move when it is your turn. Enter card numbers as a zero-based index, and colours as lowercase strings. (I'll tidy that up later)

Graphical game

A graphical version of the game can be played, developed using pygame-zero.

Install pygame zero with:

sudo pip3 install pgzero

And run the game with:

pgzrun uno_pgz.py

About

Python (re-)implementation of the card game Uno using DoublyLinkedCircularLists (in this case, DoublyLinkedCircularPlayerLists).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%