Browse Source

aces now worth 11 or 1

Vincent Sima 6 years ago
parent
commit
208d5b35f9
1 changed files with 8 additions and 0 deletions
  1. 8
    0
      src/main/java/io/zipcoder/casino/BlackJack.java

+ 8
- 0
src/main/java/io/zipcoder/casino/BlackJack.java View File

@@ -130,8 +130,16 @@ public class BlackJack {
130 130
 
131 131
     private int calcHand(ArrayList<Card> hand) {
132 132
         int totalScore = 0;
133
+        int aceCount = 0;
133 134
         for (int i = 0; i < hand.size(); i++) {
134 135
             totalScore += getCardValue(hand.get(i));
136
+            if(getCardValue(hand.get(i)) == 11){
137
+                aceCount++;
138
+            }
139
+        }
140
+        if(totalScore > 21 && aceCount > 0){
141
+            totalScore -= 10;
142
+            aceCount--;
135 143
         }
136 144
         return totalScore;
137 145
     }