samedi 28 mars 2015

Logic for Blackjack Game



I am coding a blackjack game and I am very far through. However, I just got to the point of adding together the score after each hand (something I thought would be easy) but Aces are proving to rack my brain endlessly. Since casinos play with multiple decks, it's possible to get up to 21 aces in the same hand mathematically.


How do I make a loop to go through an ArrayList of Integers called Hand which has ints which correspond to the cards that are in the hand. EX. A player hits and now has a Ace, a 5, a 2, a King, and now draws an Ace. The arraylist to represent his hand is [1, 10, 2, 5, 1]


My idea:



public void calculatePlayerScore()
{
int counter = 0;
int aceCount = 0;

for (int i = 0; i < hand.size(); i++)
{
if (hand.get(i) != 1)
{
counter++;
}
else
{
aceCount++;
}
}

for (int i = 0; i < aceCount; i++)
{

//Now that we know the regular cards
//and we know how many aces there are
//we should be able to loop to find the most
//optimal score without busting, and pick the highest among those

}


If anyone has an idea for this, please let me know. Thanks so much for the help.




Aucun commentaire:

Enregistrer un commentaire