- Home /

# Help with Blackjack Probability Concept

Hi, I have created a functioning Blackjack game and want to add a unique feature so that there is some text on the screen that shows the user the probability of the next card making them bust if they click hit. However, I don't know a good way of doing this in unity. I would have to look through the deck and their values and then work out how many cards would make the users hand value higher than 21 and then divide that by the number of cards remaining in the deck, I think. Any help is much appreciated. Thanks

**Answer** by surfuay
·
Apr 09, 2019 at 06:03 PM

this is not meant to sound mean so sorry

just look up on google the base math equation that does just that.

then adapt it to code.

to get it to show in your screen you'll need 2 things

public float bustChance

and

public text bustText

public void update () { Equation() bustText.text = "" + bustChance;

}

public void Equation() { bustChance = equation

the equation may be multiple lines }

**Answer** by azilvl
·
Apr 09, 2019 at 06:18 PM

something like this would approximately calculate the odds of getting over 21

```
float odds = Mathf.Max(0, 13 - (21 - playersHandValue)) * 4 / 52;
// Can be simplified to:
float odds = Mathf.Max(0, playersHandValue - 8) * 4 / 52;
```

keep in mind this is just an approximation and doesn't take into account that some of the cards have been drawn. if you truly want to get the exact odds you'd have to do what you already know.

```
int losingCardsCount = GetNumberOfRemainingCardsWithValueOverInt(21 - playersHandValue);
float odds = (float)losingCardsCount / (float)totalRemainingCardsInDeck;
int GetNumberOfCardsWithValueOverInt(int num)
{
//go through each card with a value bigger than num and count how many of them are left
//if you have a list of cards you can do this:
//List<Card> remainingCards = new list<Card>();
//remainingCards = allCardsList.FindAll(x => x.value > num && x.hasNotBeenDrawn);
//return remainingCards.count;
}
```

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

cpu logic in cards game 0 Answers

What's the best way to couple logic and rendering in a card game? 1 Answer

Adding id variable # to instantiate-ed object 2 Answers

TransformPoint and InverseTransformPoint 2 Answers

How destroy a object and it's similars 4 Answers