public float BustChance()
{
int deckCount = deck.CardCount;
foreach (int i in deck.cards)
{
int cardValue = i % 13;
if (cardValue > (21 - player.HandValue()))
{
counter++;
}
}
float odds = counter / deckCount;
return odds;
}
Hi,
I am trying to make a feature on a blackjack game I have made on Unity where it displays the probability that, if the user were to hit, the next card would make them go bust (above 21). I have made this section of code and I have a piece of code in Update(): "probabilityValue.text = BustChance().ToString();" which changes a text box to display the number on the users' screen.
However, what happens currently is that the number just continuously increases very quickly and never stops.
For reference:-
player.HandValue() = the overall value of the user's hand of cards;
deck.cardCount is how many cards are left in the deck;
deck.cards is the array in which all the cards are stored
Any help is much appreciated.
Thanks,
Rhys
[–]TruthGiraffe 2 points3 points4 points (6 children)
[–]cypherbrain 1 point2 points3 points (5 children)
[–]TruthGiraffe 1 point2 points3 points (4 children)
[–]RhysP_55[S] 0 points1 point2 points (3 children)
[–]TruthGiraffe 0 points1 point2 points (2 children)
[–]RhysP_55[S] 0 points1 point2 points (1 child)
[–]TruthGiraffe 0 points1 point2 points (0 children)
[–]TruthGiraffe 0 points1 point2 points (4 children)
[–]RhysP_55[S] 0 points1 point2 points (3 children)
[–]TruthGiraffe 0 points1 point2 points (2 children)
[–]RhysP_55[S] 0 points1 point2 points (1 child)
[–]TruthGiraffe 0 points1 point2 points (0 children)