The code referred to dealer instead of self.dealer when resetting the dealer's cards in the refreshPlayerCard method, leading to a potential NameError because dealer isn't defined in the method's scope.
No shuffling of the card deck:
In the genDeck method, while generating the deck, the cards were not shuffled. Without shuffling, cards would be drawn in the same predictable order, affecting randomness.
Ace value adjustment issue:
The value of the Ace ('A') was always considered as 11 points in the getScore method. When the total score exceeded 21, the value of Ace should be adjusted to 1. However, this was not implemented until after calculating the score. The logic was also missing in the main loop.
Betting issues:
There was no validation for whether players had enough money to place their bet, potentially leading to a situation where players could bet more than they have.
Game logic errors in playRound3:
The conditions for determining the winner between the dealer and players were sometimes logically incorrect, causing errors like displaying both "dealer wins" and "dealer loses" for the same player. This was due to improper use of elif blocks that didn't adequately cover all possible scenarios.
Duplicate result outputs:
Some conditions in the playRound3 method led to duplicate results being printed, especially in cases where both the dealer and the player went bust (score > 21).
Missing adjustAceValue method call:
The logic to adjust the value of Ace wasn't invoked automatically after drawing cards. Players with Ace cards could exceed 21 without adjusting the value of their Ace cards.
Changes made:
Fixed the refreshPlayerCard method: Now using self.dealer instead of dealer to clear the dealer's cards.
Modified getScore to call adjustAceValue: This ensures Ace values are adjusted properly if the score exceeds 21.
Added random.shuffle in genDeck: This shuffles the deck after generation to randomize card draws.
Revised removeLossers: Changed to filter the player list using a list comprehension, removing players with no money.
Minor issues in the code are as follows:
Incorrect use of
dealer
inrefreshPlayerCard
:dealer
instead ofself.dealer
when resetting the dealer's cards in therefreshPlayerCard
method, leading to a potentialNameError
becausedealer
isn't defined in the method's scope.No shuffling of the card deck:
genDeck
method, while generating the deck, the cards were not shuffled. Without shuffling, cards would be drawn in the same predictable order, affecting randomness.Ace value adjustment issue:
getScore
method. When the total score exceeded 21, the value of Ace should be adjusted to 1. However, this was not implemented until after calculating the score. The logic was also missing in the main loop.Betting issues:
Game logic errors in
playRound3
:elif
blocks that didn't adequately cover all possible scenarios.Duplicate result outputs:
playRound3
method led to duplicate results being printed, especially in cases where both the dealer and the player went bust (score > 21).Missing
adjustAceValue
method call:Changes made:
Fixed the
refreshPlayerCard
method: Now usingself.dealer
instead ofdealer
to clear the dealer's cards.Modified
getScore
to calladjustAceValue
: This ensures Ace values are adjusted properly if the score exceeds 21.Added
random.shuffle
ingenDeck
: This shuffles the deck after generation to randomize card draws.Revised
removeLossers
: Changed to filter the player list using a list comprehension, removing players with no money.