The Challenge
I was looking into small code examples for a specific language as a small tutorial and came accross a simplified Blackjack that should be implemented. In this Challenge you will have to implement a full Blackjack game, with 5 Decks.
The Game
You are playing against a Dealer and he has 5 Decks of Poker playing cards.
A pokerdeck contains the cards "2♠","3♠",...,"K♠","A♠","2♥",...,"A♥",...,"A♣", which may be represented by their values for 2-10, Jack-King is all 10, Ace is 11.
The gamecycle begins with the Dealear giving a card to you, and one to him self. Your goal now is to reach 21, by adding the values of the cards, that the dealer gives you.
After recieving a card, you have two options:
Stay: You decide, to not be dealt additional cards, therefore determining your score for the round: the sum of cards. For example: you have a 2, a 10, and a 8, and you decide to stay, then your score for the round is 20.
Hit: You decide to be dealt an additional card. This can lead to three cases:
- The total sum of your cards is under 21: Nothing really happens. Here you could again decide wether to stay or to hit again.
- The total sum of your cards is exactly 21: This is the best score you can get, and makes you automatically stay. If you get 21, with 2 cards (i.e.: 10 + Ace, this is called a "Blackjack") you automatically win. Else there is still possibilities for a draw.
- The Total sum of your cards exceeds 21: You busted. this is automaticaly a loose.
This is done, until you decide to stay/bust/get blackjack. Then its the Dealers turn, if you havent busted. The dealer does exactly the same. He stays/hits normally, until his score is above 17 (This is his strategy for winning). If the Dealer busts, meaning his score is above 21, you automatically win, if you havent busted yourself.
After this both you and the Dealer should have a score (i.e.: Player 20, Dealer 18). In this case the person with the higher score wins. If you draw, you draw.
The Strategy
The best strategy for the game looks like this:
Our case is slightly easier, as you cant Double and Split.
Additional notes
You may decide how to handle user input (there should obviously be some, due to the way this game is reactive), and how to do output. The carddrawing should be random, and semi-nonreproducible (C example would be: srand(time(0))
).
Rules
Standard Golf rules. Shortest byte amount wins. As this is random, there arent really any good testcases, but it should look something like this:
~$ ./blackjack
You got [10]
Dealer got [7]
Suggested: Hit
[s]tay
[h]it
h
You got [3]
Suggested: Hit
[s]tay
[h]it
h
You got [7]
Suggested: Stay
[s]tay
[h]it
s
Dealer got [9]
Dealer got [10]
Dealer busted. You won.
Another round? [y/n]: y
Next round:
You got[10]
...
Unexpected input may result in undefined behaviour.
Extra
Try and include Split/DoubleDown in both userinput and Suggested moves :) Good Luck.
Notes
If my explanation of the game was satisfying for you needs here is the Wikipedia page, to the game.