Is there a question in there?
Create a Matlab program that allows a user to play blackjack (sometimes called "21"). For those of you unfamiliar with the popular casino game, the rules can be found here and on many other websites. Blackjack essentially is a game of chicken between a player and a dealer to see who can get closest to 21 without going over.
The player may start with a maximum of 1000 chips and the maximum bet per hand is 100 chips.
There are some special rules that vary from casino to casino. In your Matlab casino, the following rules apply:
- If you get dealt a "blackjack" you get paid 3-to-2 instead of 1-to-1. If the dealer has a blackjack too you "push" and do not get paid.
- The dealer hits on a "soft-17" and stays on a "hard-17."
- You may "split" your cards only once per turn. Once you split your cards, you may play out both hands normally (you may "hit" until you get to 21 or over, "stay" and receive no more cards, or "double down" on the first two cards of each hand)
- You may "double down" on your first two cards. If you split your hand, you may double down on the first two cards of both hands.
- You may take "insurance" equal to half the original bet. If you win the insurance bet you get paid 2-to-1.
- If you dislike your first two cards, you may "surrender" for half your bet and start another hand.
The user may decide to play against a dealer who deals (1) an infinite deck or (2) a finite number of decks which the user selects (in Vegas, you can find blackjack tables that use 1-8 decks). If the user chooses option (2), reshuffle the decks after 70% of the cards have been used.
Well How do I create this programs with the guidelines given?
BTW here is the link to the rules to BlackJack: Blackjack - Wikipedia, the free encyclopedia
To extend on CB's comment, you will find that the more effort you put into your post the better the resposes will be. Post up some code so we at least know what level you are at and how you are looking to approach the problem. The reason I think that this is so important is that we all have different ways of approaching the same problem. For example, I would not have generated a random list of numbers like CB did, I probably would have gone with a random indexing approach just because thats what I find simplest to picture:
Both methods will work, CB's method would probably lead to some tidier code in places but neither is right or wrong. There is no point of us posting up code that isn't going to be of any benefit to yourself.Code:Ndeck=6; deck=repmat([1:52],1,Ndeck) rand_card_index = round(numel(deck)*rand()) rand_card = deck(rand_card_index)%get card deck(rand_card) = []%remove card
Elbarto
I built a similar blackjack program just recently with Mathematica and used this place to get all of my info: Play Blackjack Online - Basic Strategy and Free Blackjack
I would recommend checking out the probability odds charts, the basic rules and stuff like that. They have an excellent card counting guide if you ever get into the advanced math regarding it.
Hope that helps.