import random # Function to simulate a match with potential tiebreaks def simulate_match(player1, player2): result = random.choice(['2-0', '2-1', '2-1_tb']) winner = player1 if random.choice([True, False]) else player2 if result == '2-0': loser = player2 if winner == player1 else player1 return (winner, 3, loser, 0, 2, 0, 0) elif result == '2-1': loser = player2 if winner == player1 else player1 return (winner, 2, loser, 1, 2, 1, 0) else: # '2-1_tb' loser = player2 if winner == player1 else player1 return (winner, 3, loser, 1, 2, 1, 1) # Initialize players and standings groups = { 'A': ['A1', 'A2', 'A3', 'A4'], 'B': ['B1', 'B2', 'B3', 'B4'] } standings = { 'A': {player: {'points': 0, 'sets_won': 0, 'sets_lost': 0, 'tiebreaks_won': 0} for player in groups['A']}, 'B': {player: {'points': 0, 'sets_won': 0, 'sets_lost': 0, 'tiebreaks_won': 0} for player in groups['B']} } # Define matches for each group matches = { 'A': [ ('A3', 'A4'), ('A1', 'A2'), ('A2', 'A4'), ('A1', 'A3'), ('A2', 'A3'), ('A1', 'A4') ], 'B': [ ('B2', 'B3'), ('B1', 'B4'), ('B1', 'B3'), ('B2', 'B4'), ('B3', 'B4'), ('B1', 'B2') ] } # Simulate all matches and update standings for group in matches: for match in matches[group]: winner, winner_points, loser, loser_points, sets_won, sets_lost, tiebreaks_won = simulate_match(*match) standings[group][winner]['points'] += winner_points standings[group][loser]['points'] += loser_points standings[group][winner]['sets_won'] += sets_won standings[group][winner]['sets_lost'] += sets_lost standings[group][loser]['sets_won'] += sets_lost standings[group][loser]['sets_lost'] += sets_won standings[group][winner]['tiebreaks_won'] += tiebreaks_won standings