Navigation

Related Articles

Filter by Category

Filter by Author

Back to Latest Articles
A “Flair” of Uno!

A “Flair” of Uno!


Amita Vaghela
Amita Vaghela
A “Flair” of Uno!

About a year ago, during the February half term in 2020, I took on the challenge of trying to code a working game of Uno using Python Programming. After using the full week of half term to code, I was able to complete this challenge and am quite proud of my achievement.

I first decided to try and code this program after an extension challenge during one of my lessons; to create a list of cards in an Uno deck using lists and loops. I completed this in class, and then I thought about how hard it would be to create the full game using Python Programming. Of course, I knew I wouldn’t be able to make a program that allows multiple people to play at once, like the real game of Uno, but I wanted to see how far I could go.

My first step was to move on from what I did in class, and try to generate random cards from the array I created. This wasn’t too hard to do, but my next step would be to save the cards in separate lists for 2 different players. Once I was able to do this, I made it so the player would be able to draw cards, and later on, play cards from their hand. After this was done, it would be possible to play the game of Uno by yourself, only getting rid of your own cards not having to worry about another player. This was boring tho, so my next challenge would be the hardest bit of programming I had done at that point, which would be to make the computer play against the player.

The basic idea of how I aimed to do this was by having a separate list of cards that contained the cards the computer could play when it was its turn, and then just choose randomly. This was easier said than done, but once completed the Uno game was pretty much completed. Adding the special cards like +2s and +4s was another challenge, but one I was able to overcome. Below is an example game that could be played, so you could see how it would play out.

However, I felt like it was missing something, and after some encouragement from my parents I worked on trying to add pictures to make it look more like Uno. I don’t know of a way to do this in regular Python, but there is a downloadable library of code (an extension to Python) that allows you to, which is called Pygame Zero. I had done some experimenting before this, and so decided to give it a try. The coding was quite a bit harder, as the game now needed to revolve around the player clicking the right cards rather than typing. Also, I needed to use images, so after spending a decent amount of time finding and cropping the card images, I had to add them to the code.

This took me the full half term to complete, with coding being the main activity I did for those few days. I got to a point where I was happy to leave it as it is, but it could still be improved. I was not able to get the “wild cards” to work in the new version, but over the last year there have been small adjustments I’ve tried to make to make it a bit better, and below you will find what the program actually looks like when it’s running.

If you’re still reading this, thank you. If you have Python yourself, here’s the link to a google doc that has the text-based version I made, which you should be able to copy and paste into a new Python file to play yourself if you are interested:

Python Programming Challenge 7.2 – Uno (text based)

Thanks again for reading! Happy Programming!

By Yehen Singankutta Arachchilage

 

 

Related Articles

Word of the Week: Beserk
Word of the Week

Word of the Week: Beserk

Posted on by Danielle Bowe
Year 7 students are gaining confidence with a STEM computing activity
IT & Computing

Year 7 students are gaining confidence with a STEM computing activity

The IT and Computing department was absolutely delighted to deliver a computing STEM activity for year 7 students during the enrichment day last week. All students had the...

Posted on by Mo Abusef