MatLab-BlackJack game problem help please!

• Mar 7th 2010, 11:01 PM
EngineeringFTW
MatLab-BlackJack game problem help please!
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.
• Mar 8th 2010, 04:03 AM
elbarto
Is there a question in there?
• Mar 8th 2010, 08:49 PM
EngineeringFTW
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
• Mar 8th 2010, 10:26 PM
CaptainBlack
Quote:

Originally Posted by EngineeringFTW
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:

Ndeck=6;
deck=mod(randperm(52*Ndeck),52)+1

will give you a randomly shuffled of 6 decks

By the way no one is going to do this for you, you have to do most of it yourself and may be ask more specific questions along the way.

CB
• Mar 9th 2010, 04:45 AM
elbarto
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:

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```
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.

Elbarto
• May 20th 2010, 10:35 PM
wickland
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.