Skip to content

Commit

Permalink
Blackjack game: fix bug counting more than one ace
Browse files Browse the repository at this point in the history
Take into account how many aces there are before using 11 as the value for an ace
  • Loading branch information
403-Fruit authored Mar 5, 2023
1 parent 920bee0 commit f1f2718
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions applications/plugins/blackjack/common/card.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ uint8_t hand_count(const Card* cards, uint8_t count) {
}

for(uint8_t i = 0; i < aceCount; i++) {
if((score + 11) <= 21)
if((score + 11 + (aceCount - 1)) <= 21)
score += 11;
else
score++;
Expand Down Expand Up @@ -350,4 +350,4 @@ void add_hand_region(Hand* to, Hand* from) {
add_to_hand(to, from->cards[i]);
}
}
}
}

0 comments on commit f1f2718

Please sign in to comment.