Class 2 |
Intermediate Java 30-IT-397 |
|
Blackjack Game
-
The object of Blackjack is to get a higher card total than the dealer,
without exceeding 21.
-
The dealer deals two cards face up to the player, one card face up and
one face down to himself.
-
The player must then make a decision. For our example, let's limit
the decisions to these three:
-
Hit: Ask for another card. Can ask for further cards if the hit card
does not bust the player's hand.
-
Stand: Do not get another card.
-
Double Down: double the bet in exchange for just one card. The player
is unable to get another card after this.
-
There is a generally accepted blackjack
basic strategy that has the mathematically correct decision to make.
Over time, this lowers the casino's advantage to .05%. This chart
is pictured at the end of this slide, courtesy of http://www.thewizardofodds.com/game/bj.html
-
This makes for an ideal Java program. But in the sake of time, let's
limit our program to this:
-
Have a class, Card.java, which represents a card's
numerical value, face value, and suit.
-
Another class, CardGenerator.java, will
pick a random card from that deck, and remove it so that it cannot be used
again.
-
Blackjack.jsp will have a scriptlet that gets
cards for the dealer and player from CardGenerator. By sharing information
with each other, the tags will then display the basic strategy decision.
It also uses the page include directive to import the blackjack package.
This package contains the two above classes.
-
Play.java is the tag handler that controls the
game, it holds the totals of the dealer's hand and player's hand.
-
DealerUp.java is a tag handler that gets the
dealer's up card value and sends that to Play.jsp.
-
PlayerHand.java is a tag handler that gets
the player's total for both cards and sends that to Play.jsp.
-
Decision.java queries Play.java for the correct basic strategy decision,
and writes that to the JSP page.
-
I'll let you figure out the .tld and the web.xml entries on your own.
-
This example could easily be modified to provide a basic strategy quiz,
or a full fledged blackjack game.
-
Use JavaScript to make the game truly interactive.
-
2-1 says I'll do just that.

The Results

Created by: Brandan Jones
December 17, 2001