In this exam, you will simulate a black jack game and investigate the effect of shuffling a card deck on the outcome of the game. Don't make this an interactive game. It is a simulation.
You MUST use the Stack class we implemented in class and I uploaded to BB. You will also define the following classes and use objects instantiated from them:
1. A Card class: you will need to hold the card suite and value (the suit is useful in printing)
2. A Deck Class which will use the Stack implementation we did as a Stack of Cards - of course you will use the push, pop, print and numOfCards as methods and attributes for an object deck instantiated from the class Deck. While you could potentially make the Deck a Stack object, it is better to make it a class inherited it from Stack and implement non stack methods that you may need later.
3. You will need a readDeck function to read the data from the provided deck file and push the data onto the Deck object - as a Stack of Cards. The file is called cards.txt.
1- First you will implement a simple shuffle algorithm using two additional Stacks of Cards to create a simple shuffle. Create a function that takes your main Deck of cards as a parameter and locally use two additional stacks (stack1 and stack2). The shuffle algorithm should pop the first half of main Deck into the first stack and the second half of the main deck to the second stack and then alternate popping one card at a time from stack1 and stack2 back into the main Deck until the two stacks are empty and all cards have been put back into the main Deck. You should now, test your function by shuffling the Deck and printing it three or four times. What do you notice? Hint: You should have a printDeck method in your Deck class.
2- Now you will implement the Fisher Yates shuffle algorithm. Explain how it works. Notice that I have added something that will help you with this in the stack implementation which is a method that would allow you to extract a specific element at a specific location from the stack rather than the top element of the stack. I also added a delete method to delete an inner node to help you with this task. Think about how you will do this to the stack once you research how this algorithm works (you simply select a random number x between 1 and n inclusive -> n being the size of the stack and you keep deleting them from the stack adding them to a list until all elements have been deleted from the stack at such a random order, at which point you copy the list back into the main deck again). Write a second shuffle function that does exactly that. You should now, test your function by shuffling the Deck and printing it three or four times. What do you notice? Compare the two algorithms and indicate why one is better if at all.
1- We will implement a simple game that includes one player and one dealer. the game we will play is a simple version of blackjack with only one player and the dealer. The dealer and the player will follow standard rules of BlackJack. You can simplify some rules if you wish such as not implement the 11 rule for and Ace.
2- The goal of each player and dealer is to get close to 21 without actually exceeding 21 in which case the person who exceeds 21 would lose the game or the game session.
3- The Value of the cards (K,Q,J,10) is 10, (2..9) is the actual value and the Ace is 1 or 11 but you can just consider the 1 case.
4- You should include a method in your Deck class to calculate the total value of the cards in a deck. This will make it easy for you to calculate the value of the player deck and the dealer deck to determine who wins each session.
5- Make your game consist of multiple sessions (you should have a Game class with player and a dealer and sessions and keep track of the number of sessions each has won)
6- Remember that if the dealer total is 21 the dealer wins. But if he is greater than 21, the player wins. If the dealer has 17 points, he stands which means he can't draw more cards. If the dealer has 16 or less, he must draw a card and continue to do so until he either gets 21, above 21 or 17.
7- For the player, if the player has 21 and the dealer is does not have 21, the player wins the game or the game session. If he exceeds 21, the dealer wins, if he has 18 or more, he stands no drawing more cards. If he has 12 or less, he keeps drawing card by card until he gets to a number that is above 17. If the player is between 12 and 17, he can randomly decide to hit or stand one time.
8- Your Game class should have two Deck objects one for player and one for dealer, and a mainDeck. You start the game by dealing one card from the mainDeck to the player and one to the dealer and keep printing the deck of each with each one's total by applying the rules until someone wins. Repeat may be 10 times per game or until the main deck is exhausted.
9- Usually several number of decks are used. Make it so that you could combine several decks and shuffle them.