Child pages
  • CS231 Project 1: Monte-Carlo Simulation: Blackjack
Skip to end of metadata
Go to start of metadata

Justin Gelwicks

CS231


Project 1: Monte-Carlo Simulation: Blackjack


Summary:

The purpose of this project was to introduce basic java data structures in order to help us get acquainted with the language. The goal of this project was to create a simulation that allows us to run a basic simulation of the game blackjack. In order to do this, we created four classes:  a card class, which set the parameters for what a card could be; a hand class, which created a list for your hand and returned a value; a deck class, which created a deck of 52 cards with four of each card; and a blackjack class, which added cards based on your current hand and decided whether you busted, and who had the higher hand, the player or the dealer.


Solution:

 There were many different implementations of these basic java structures throughout the project. For example, the deck class created an array list of type Card with an initial 52 values; the hand class also created an array list but included several other methods. The getTotalValue method looped through the deck and added the value of the card to the total.


When returning the total value we got the value of the hand. The blackjack class ran games of blackjack by adding cards based on player and dealer trends of hitting until 17 and 16 respectfully. I made a toString method, the difference between a tostring and just printing out the values is that the toString returns them.

The final step of this project was to create a simulation that ran many games of blackjack and returned the percentage of games were pushes, dealer wins, and player wins. The dealer wins more than the player does, and I came to the conclusion that this consistently happened running blackjack about 350 times. The simulation class runs the blackjack file 1000 times, which is plenty for accurate representation:


Conclusion:

This project was a great dive into Java; I was –and am– very intimidated by java, but it is pretty clear that there are many similarities to python as well as many small details that make it frustrating to adjust. There are also many new ideas that I learned while doing this project– the most noteworthy is the use of individual files for classes. Arraylists were also an enlightening new way to store data and played a key role in my deck and hand classes. All-in-all, this was a fun, game-style way of learning the language.


Collaborators:

TA: Ethan

Bret Miller

Haemi Lee

Dylan Walsh