Write a program that plays the game of Blackjack. The main idea of Blackjack is to get a hand of cards that adds up as close as possible to 21 without going over. We will use the following rules:
Your program should have the following capabilities:
increment = (prob12 - probHigh)/(highHit - 12);With the numbers above we get (1 - 0.5)/(17 - 12) = 0.1 so the probabilities decrease .1 (10%) for each point above 12.
double probHit; // probability of hitting on the current count // (between 12 and highHit probHit = prob12 - increment * (count - 12); // generate a random number between 0 and 1 - say you store it // in the variable rand rand = ________________________________; if (rand < probHit) computer hits else computer sticks
The Program Structure
Your program should have the following structure:
You may need other methods but don't get too carried away.
Sample output (when the player is the human user):
Welcome to the Blackjack Casino! =============================== Please enter the player's name (or enter Computer): Bozo Dealing Bozo's hand... Cards are 8 of Diamonds and 5 of Hearts Count is 13 Dealing Dealer's hand... Top card is 10 of Clubs Bozo's turn... Do you want to hit or stick (h or s)? h New card is 6 of Clubs Count is 19 Do you want to hit or stick (h or s)? s Dealer's turn... Bottom card is 4 of Diamonds Count is 14 Dealer hits... New card is 3 of Spades Count is 17 Dealer sticks... Bozo's count is 19 Dealer's count is 17 Bozo wins! Play again? ....
Sample output when the player is the computer:
Welcome to the Blackjack Casino! =============================== Please enter the player's name (or enter Computer): Computer Enter the probability of hitting on a count of 12: 1 Enter the highest count for a hit: 17 Enter the probability of hitting on a count of 17: 0.5 Dealing Computer's hand... Cards are 6 of Diamonds and 5 of Hearts Count is 11 Dealing Dealer's hand... Top card is 10 of Clubs Computers's turn... Computer hits... New card is 5 of Clubs Count is 16 Computer hits... New card is 9 of Spades Count is 25 Computer busts Dealer wins! Play again? ....
Counting the Ace as 1 or 11
In real Blackjack, the ace can have a point value of 11 or 1. Generally it is an 11 unless that makes the total count go over 21. When the total count includes an ace counted as an 11, the count is called soft. If a new card is dealt that puts the count over 21 if the current count is soft 10 points are deducted and the count is no longer soft. In most games the dealer always uses a soft count; that is, the ace is always valued at 11.
You should get your program working correctly always counting the ace as a 1 before getting it to work for 1 or 11 (see grading below).
Grading Your program will be graded both on style and correctness. Style includes adherence to rules for naming of identifiers and use of white space; it also includes coding style such as the absence of unnecessary code (extra comparisons in if's or extra assignments); it includes good class design (appropriate choice of instance variables and methods); it includes appropriate documentation. Style will be 20% of the grade on the assignment. Correctness includes meeting all the specifications of the assignment. A program that does not compile has an automatic deduction of 70%; one that does not run has an automatic deduction of 40% no matter how "close" it is to compiling or running. Come see me if you have problems with the assignment. It is important that you get in the habit of producing correct programs!
Academic Integrity Reminder!!! Programming assignments are to be your own work. You may get help on the specifics of the assignment from no one except the instructor. You may not show your program to anyone or look at anyone else's program or share ideas with anyone about how to write the program.
Hand IN: A printed copy of your program files. Tar the .class, .html, and .java files and email the .tgz file to email@example.com with a subject of cpsc120 project3.