66 lines
2.6 KiB
Python
Executable File
66 lines
2.6 KiB
Python
Executable File
from game_logic import deal_card, calculate_hand_total, has_blackjack
|
|
|
|
class BlackjackGame:
|
|
def __init__(self):
|
|
self.player_hand = []
|
|
self.dealer_card = 0
|
|
self.player_total = 0
|
|
self.has_blackjack = False
|
|
self.stats = {
|
|
"total_rounds": 0,
|
|
"correct_decisions": 0,
|
|
"incorrect_decisions": 0,
|
|
"by_scenario": {
|
|
"hard_totals": {"correct": 0, "incorrect": 0},
|
|
"soft_totals": {"correct": 0, "incorrect": 0},
|
|
"pairs": {"correct": 0, "incorrect": 0},
|
|
},
|
|
"current_streak": 0,
|
|
"longest_streak": 0,
|
|
"last_round_won": None,
|
|
"pending_streak_notification": None
|
|
}
|
|
|
|
def update_stats(self, correct_decision, scenario_type):
|
|
"""Update statistics based on the user's decision."""
|
|
self.stats["total_rounds"] += 1
|
|
|
|
if correct_decision:
|
|
self.stats["correct_decisions"] += 1
|
|
self.stats["by_scenario"][scenario_type]["correct"] += 1
|
|
|
|
if self.stats["last_round_won"] is None: # First decision
|
|
self.stats["current_streak"] = 1
|
|
elif self.stats["last_round_won"]: # Continuing streak
|
|
self.stats["current_streak"] += 1
|
|
else: # New streak after loss
|
|
self.stats["current_streak"] = 1
|
|
|
|
self.stats["last_round_won"] = True
|
|
self.stats["longest_streak"] = max(self.stats["longest_streak"], self.stats["current_streak"])
|
|
|
|
else:
|
|
self.stats["incorrect_decisions"] += 1
|
|
self.stats["by_scenario"][scenario_type]["incorrect"] += 1
|
|
|
|
if self.stats["current_streak"] >= 3:
|
|
self.stats["pending_streak_notification"] = (
|
|
f"🔥 Streak ended at {self.stats['current_streak']}!"
|
|
)
|
|
|
|
self.stats["current_streak"] = 0
|
|
self.stats["last_round_won"] = False
|
|
|
|
def get_stats(self):
|
|
"""Return the current statistics."""
|
|
stats = self.stats.copy()
|
|
if self.stats["pending_streak_notification"]:
|
|
self.stats["pending_streak_notification"] = None
|
|
return stats
|
|
|
|
def start_new_round(self):
|
|
"""Deal initial cards and reset the game state."""
|
|
self.player_hand = [deal_card(), deal_card()]
|
|
self.player_total = calculate_hand_total(self.player_hand)
|
|
self.dealer_card = deal_card()
|
|
self.has_blackjack = has_blackjack(self.player_hand) |