In your last few rounds of Blackjack, you have been losing horribly, but you think you may just have been unlucky. To calculate this, you want to figure out the maximum amount of money you could have made, had you played perfectly. You record all the cards that were dealt in the order they were dealt, and create a program to figure out the most money that could have been made from those cards, given your starting money and the amount you always bet.
The game of Blackjack is simple to learn, yet hard to master. Out of some combination of standard 52-card decks, you get two cards, and the dealer gets two cards. The dealer gives one card to you, then one to himself, then a second card to you, and finally a second card to himself. Cards with rank 2 through 10 are valued at their rank. Jacks, Queens and Kings are worth 10 points. Aces are worth 11 points, but if 11 points will put you over 21, the Ace's value reduces to 1 point. The goal is to beat the dealer's points and not go over 21. You must choose whether to "hit" (take another card from the deck to add to your score) before the dealer plays. You may hit as many times as you want while your score is under 21 (you cannot hit with a score of 21). If your score exceeds 21, you "bust", and the round is over. If you "stay" (stop hitting when your score is less than or equal to 21), the dealer plays his turn. The dealer plays according to a simple rule -- while his score is below 17, hit. If the dealer stops on a score less than your score or busts, you win. If you bust, or the dealer's score is greater than yours, you lose your bet. If you have the same score, it's called a "push" and you get back the money you bet for that round. Except for several special situations, when you win you receive the amount you bet. The special situations follow:
Being dealt an Ace and a card worth 10 points results in a starting score of 21, and is called Blackjack. If you or the dealer gets Blackjack on the first two cards dealt, no cards are allowed to be drawn. The scores are compared, and if you win, you receive one and a half times your bet. If you tie, it is a push. If you lose, you just lose the bet.
Doubling down is a way of increasing your winnings by increasing your bet once you see your first two cards. When you double down, you double the bet for this round, and you take exactly one more card from the deck. No matter what card that is, you cannot continue taking any more cards. You can only double down if:
- You have not taken a hit.
- Your first two cards total 10 or 11, or your first two cards are an Ace and a nine (in any order).
- You have sufficient funds to double your bet.
Your method will be given a String cards that represents the cards in the order dealt, an int bet that represents the amount you bet for each round, and an int money that represents your starting money. Each character in cards will be one of '2'-'9', 'T' (Ten), 'J' (Jack), 'Q' (Queen), 'K' (King), or 'A' (Ace). You are to return an int representing the maximum amount of money you could end with after playing through all the rounds that are possible. You are not allowed to stop playing as long as there are more cards in the deck and you have enough money to keep playing. However, if you are playing a round and run out of cards, this is considered a push, and you keep your bet. See examples 4 and 5 for clarification. You must stop playing if you do not have enough money to make the bet for the next round.