# card game

Assignment 3 – The card game: War
Penalties: No late assignments allowed
Maximum Marks: 10
Pedagogical Goal: Refresher of Python and hands-on experience with algorithm coding, input validation, exceptions, file reading, Queues, and data structures with encapsulation.
The card game War is a card game that is played with a deck of 52 cards.
The goal is to be the first player to win all 52 cards. It is played by two players but can also be played with more.
The deck, after being shuffled, is divided evenly between the players. When there are two players each one receives 26 cards, dealt one at a time, face down. So the cards and their order are unknown. Each player places their stack of cards face down. It may seem as a STACK as we know it, since the player takes and plays one card at a time from the top of this stack. However, it is more like a QUEUE, since as we shall see it, when a player wins cards, these are placed at the bottom of this stack of cards.
How do we play the game
Each player turns up a card at the same time and the player with the higher card takes both cards and puts them, face down, on the bottom of their stack.
If the cards are the same rank, it is War. Each player turns up one, two, or three cards face down (so they are not seen) and one card face up. The player with the higher cards face-up at the end takes both piles (six, eight or ten cards). If the turned-up cards are again the same rank, it is War again and each player places another set of cards (one, two or three) face down and turns another card face up. The player with the higher card face-up at the end takes all placed cards, and so on. The game continues until one player has all 52 cards and is declared the winner. There are three versions of this game depending upon the number of cards we place face-down when there is War: one card, two cards, or three cards. It remains consistent throughout the game.
A deck of cards:

A deck of 52 cards has four suits: diamonds, clubs, hearts, and spades). In each suit, we have the King, the Queen, the Jack, the Ace, and cards from 2 to 10.
The Ace is the highest rank, followed respectively by the King, the Queen, the Jack then the cards 10 down to 2. Cards from different suits but with the same rank are equivalent.
To display the cards on the screen, we use two characters to represent a card. The first character is the rank and the second the suit. The rank is either K for king, Q for queen, J for Jack, A for Ace, then 2 to 9 for the numbers and 0 for 10. The suits are D, C, H, and S. Example 8D is eight of Diamond; 0H is 10 of hearts.

You are given a text file of 52 shuffled cards, each card is in a line coded on two characters as described above. You need to prompt the user for the name of the file, open the file and read it. Make sure the file exists and make sure the cards in the file are correctly formatted as described above. If the cards are in lower case, it is not an error as you can simply transform them in upper case. You can assume the cards are shuffled but don’t assume they are formatted as specified or that there are exactly 52, or even that they are not repeated. Make sure all the standard 52 cards are there in the shuffled deck. You are not asked to correct the cards, but your program must raise and catch an exception if card validation does not go through. The program should then display an appropriate error message and terminate the program in case there is an issue with the cards.
You are given a python program shuffleCards.py that generates the file shuffledDeck.txt as we described above with 52 lines constituting the shuffled deck. However, while this program generates a correct input to your program don’t assume the input file is always correct. The assessment of your assignment may be made with a file that is incorrect.