The goal of this assignment is to simulate a version of the Blackjack game, one of the most popular games played in the casinos. Specifically, you will program the dealer and the players at the table.
The game begins with the dealer shuffling a single standard deck of 52 playing cards. The game then proceeds in rounds. In every round, each player places a bet amount on the table before any cards are dealt. The dealer then deals one open card to every player on the table and one card for herself. She then deals the second open card to all the players and a closed card for herself. Once the initial cards are dealt, each player plays the round with the dealer separately.
The value of cards 2,3,...,10 is equal to their rank. The value of a King, Queen, or Jack is always 10. An Ace can be counted as either 1 or 11. The value of a set of cards (hand) is equal to the sum of the value of the individual cards. Note that the suit of a card has no impact on its value.
In a round, a player chooses one of the following 3 options:
Once all the players finish their play, the dealer reveals her closed card. She continues to draw cards until the first time the value of her hand can be greater than or equal to 17.
After all the winning amounts are settled, the dealer collects all the cards dealt in that round and piles them in a different stack. Cards should be collected one player at a time in the order they were dealt, followed by the dealer's cards. In future rounds, whenever the dealer runs out of cards to deal, she shuffles the cards from the piled up stack and places them in the play stack.
Your goal is to simulate the Blackjack dealer and multiple players
in the functional programming subset of the Oz programming
language. This means that you should not use objects or explicit
state, only functions. Furthermore, you should not use
for
and while
loops for control flow, but
instead use recursion.
Each player starts with a fixed initial amount and bets a certain amount each round. All the players play with the exact same strategy. The table shows the player choices depending on the current value of their hand.
Note that the value of an ace card should be treated as 11 if that would result in the total hand value being 21 or less and 1 otherwise (if 11 would bring the value of the hand over 21.)
local A=333667 B=213453321 M=1000000000 in
  proc {NewRand ?Rand ?Init ?Max}
    X = {NewCell 0} in
    fun {Rand} X := (A*@X+B) mod M end
    proc {Init Seed} X := Seed end
    Max = M
  end
end
Write a main function that simulates the Blackjack game play
between the dealer and the players. It should be possible to call your
function in the following way: {Browse {BlackJack S N M B
R}}
Seed for the pseudorandom number generator | |
Number of players at the table | |
Initial amount of money for each player | |
Amount that each player bets per round | |
Maximum number of game rounds to simulate |
Make the following assumptions in your program.
The output of the BlackJack function should be a tuple in the
following format:
game(M [R1#M1 R2#M2 … Rn#Mn])
where M
is the amount of money the dealer has at the end of the game, R
is the number of turns that each player stayed in the game and M
for each player is the amount of money the player finished the game with.
For extra credit, you can add two additional features for each player.
If both the cards in a player's hand have the same rank, the player may choose to split the hand into two separate hands by placing an equal bet on the new hand. For example, consider the case when a player's initial hand is [4Club, 4Diamond] and his bet for the round is 10. When it is his turn to play with the dealer, he can split the hand into two hands [4C] and [4D] by placing additional 10 on the new hand. Your program should also allow a player to split a hand that is already split. In the example, suppose the player is dealt [4Heart] for the [4C] hand then he may choose to split the hand again. He will be playing with three separate hands with a bet of 10 on each hand. The table below provides the strategy for when a player should split:
Each player in the program should be able to employ high-low card counting strategy to alter the bet amounts after each round. The basic idea of card counting method is to track the count variable through the entire game. At the beginning count is 0. The value of count changes whenever an open card (X) is placed on the table as shown below. It is reset to zero when the cards are reshuffled.
Count=Count+ |
1 |
2 |
0 |
7 |
|
-1 |
The player in your program should bet twice the normal amount if the value of the count variable is at least +2.
Due Date:
Received Time | Grade Modification |
before Sunday, 10/05, 11:59PM | +10% |
before Monday, 10/06, 11:59PM | no modification (on time) |
before Tuesday, 10/07, 11:59PM | -10% |
before Thursday, 10/09, 11:59PM | -25% |
after Friday, 10/10, 12:00AM | not accepted |
Grading: The assignment will be graded mostly on correctness, but code clarity / readability will also be a factor (comment, comment, comment!). See the professor or TAs, if you have ideas for other extensions for this assignment and would like extra credit for implementing them.
Submission Requirements: Please submit a ZIP file with your code, including a README file. In the README file, place the names of each group member (up to two). Your README file should also have a list of specific features / bugs in your solution. Your ZIP file should be named with your LMS user name(s) as the filename, either userid1.zip or userid1_userid2.zip. Only submit one assignment per pair via LMS.