Skip to end of metadata
Go to start of metadata
  • Description
    • In this project, I created a rudimentary game of the popular card game blackjack. In addition to creating the game, I also simulated a thousand runs to find overall win percentages. I found that in the player typically loses the game in the long-run.
  • Solutions
    • I accomplished this by creating a number of different classes: Card, Hand, Deck, Blackjack, Simulation. The Card class basically just holds a number. The Hand class holds an ArrayList of Cards which are used for the dealer and player. The Deck class basically just holds 52 Card objects and lets the user pick/shuffle cards. To shuffle the deck, I created a second deck, and randomly selected values from that deck to add to a new list. I then set the original deck equal to the new list so that the deck would reference the "shuffled" deck. The Blackjack class brought together all of the components to actually play the game. The playerTurn and dealerTurn functions basically just keep adding cards to the respective hands based depending on if the player's hand value is < 16 or the dealer's is < 17. The Simulation class was just a main method that played a set number (default: 1000) games of Blackjack and tracked the statistics of who won.
  • Are 1000 games sufficient to provide an accurate estimate of the win percentage for the player and dealer? What are those percentages?
    • No, there is significant variability with 1000 games. In general, the player win percentage was around 40-44% and the dealer win percentage was around 47-50% with the remaining percent being pushes. A 3-4% swing is rather a significant amount.
  • What is the number of games the simulation has to play in order for the dealer's win percentage always to be above the player's win percentage over ten runs of the simulation?
    • I tried 5, 10, 100, 500, and 1000. 1000 games was the only one where 10 runs of the simulation resulted in the dealer always having a higher win percentage. I went up to 50 runs of 1000 games and still had the dealer win percentages consistently above the player win percentages.
  • Results of the overall simulation.
  • Extensions:
    • Changing shuffle timing
      • I started off shuffling when there 40 cards remaining and then gradually dropped it down to 15. From a few tests, shuffling with less cards left in the deck resulted in a lower win percentage for the player.
    • Interactive
      1. Uses
      2. This extension lets the player decide whether to hit or stand.
      3. I used the Scanner class in my playerTurn function so that I could get the player's input.
    • Make your game use 6 decks, and reshuffle if only 1 deck left. Play the game 1000 times, and observe how many games the player wins, how many the dealer wins, and many are pushes.
      1. Uses and modified lines of
      2. I changed the number of cards added to the deck in and also changed when it would shuffle.
    • Different Decision Rules
      1. For this extension, I ran 3 simulations of 10 million games of every condition from 10-20.
        1. Found that hit if under 13 was the optimal condition for the player to win. My guess as to why the player always has a sub-50 win rate is because the player goes first and thus can end the game by busting first.
    • Standard Deviation
      1. Use
      2. I created a new Simulation class that let me run 50 simulations of M games. I then made it so that it would calculate the standard deviation for each set of 50 runs of M games. I ran it where M = 10,50,100,500,1000,5000,10000,100000,1000000. I ran each standard deviation calculation 5 times and then averaged the standard deviations to calculate a final standard deviation for each set of 3-50-M games. I then used Excel to graph these averaged standard deviations. After 1000 games or so, the standard deviations are very low. 
  • A brief conclusion and description of what you learned
    • I strengthened my understanding of object-oriented programming by using a number of different Class to achieve a singular goal. I brushed up on my knowledge of the rules of blackjack. I learned that compiling the files every time I want to run something is incredibly annoying, and that I will try to do most of my programming in Eclipse from now on. I refreshed my knowledge of Java.
  • People who helped me
    • I tried using StackOverflow to have Kenny Roger's "The Gambler" play while my blackjack game ran, but I couldn't legally find an uncompressed .wav file and the .wav I did acquire seemed to be a compressed .wav which was not supported by the audio library I tried to use. I asked Bruce a couple questions during lab.