# CS441 Systems Biology II cs231f09project1

This project simulates playing Blackjack using many classes connected with has-a relationships.

To shuffle the deck, I made a new, empty, deck and transfered the cards from the original deck to the new deck in a random order.

I'm not sure what the scores in Blackjack were supposed to represent, so I never used those fields.

I added a toString() method to BasicCard to make BasicDeck's print() easier to write.

To run the simulation, I used a for-loop that called playGame(), storing the returned value in a variable. Using conditional statements, I incremented the appropriate counter. Once the for-loop was completed, I calculated the percentages by dividing the counters by the the number of trials, which I had stored in a variable for this purpose. I created a static method to calculate the percent so that I could format the result since I could not remember how to use DecimalFormat and I decided it would be just as easy to write my own method as it would be to search the Java API.

the results of my simulation are as follows:

1.

initially:

The player has [4, 5]

The dealer has [3, 1]

At the end,

The player has [4, 5, 10]

The dealer has [3, 1, 2, 7, 9]

The dealer went bust, so the player wins.

2.

initially:

The player has [10, 7]

The dealer has [10, 9]

At the end,

The player has [10, 7]

The dealer has [10, 9]

The dealer wins.

3.

initially:

The player has [5, 10]

The dealer has [4, 9]

At the end,

The player has [5, 10, 9]

The dealer has [4, 9]

The player went bust, so the dealer wins.

extensions:
I adapted my code to allow aces to be used as 11's, and therefore enabled the player to make more educated decisions. Because playerTurn() and dealerTurn() were getting lengthy and repetitive, I created a genericTurn() that took as arguments the hand and the maximum values for hits. To determine the softMax for the player, I ran the simulator for several values and got the following results:

for hitting only up to (not including) a soft 16:

The player won 41.89%

The dealer won 49.39%

There were pushes 8.70%

for hitting only up to (not including) a soft 17:

The player won 41.79%

The dealer won 49.27%

There were pushes 8.93%

for only hitting up to (not including) a soft 18: ***BEST****

The player won 42.50%

The dealer won 48.87%

There were pushes 8.62%

for hitting up to (not including) a soft 19:

The player won 42.24%

The dealer won 48.99%

There were pushes 8.76%

for hitting up to (not including) a soft 20:

The player won 41.83%

The dealer won 49.40%

There were pushes 8.76%

In conclusion, to complete this problem, I learned more about the game Blackjack. I already knew the Java constructs and OOP concepts involved in this problem, but did learn how to create a wiki page to complete the project.

Labels