Package: tennis
Python Tennis LibraryThe Tennis library is a Python package that provides functionalities for simulating tennis matches and tiebreakers. It offers easy-to-use methods to simulate and track scores, tiebreakers, and various statistics. The tennis library is perfect for tracking real time data input.FeaturesThe Tennis library offers the following main features:1. Match SimulationThe match simulation feature allows you to simulate a full tennis match between two players. It will automatically keep track of match stats and comply with complicated rules like tiebreakers, AD, and serving2. TiebreakerThe tiebreaker feature enables you to simulate a tiebreakerIt provides an easy-to-use interface for conducting tiebreakers, scoring points, and tracking statistics.Tracking StatsBoth the match simulation and tiebreaker features include built-in mechanisms for tracking various statistics. These statistics include:AcesDouble faultsFirst serve percentageFirst serve points wonSecond serve percentageSecond serve points wonServe games wonReturn games wonWinnersUnforced errorsPoints won by volleyPoints won by dropshotPoints won by overheadThese statistics help analyze player performance and provide insights into the gameplay.UsageTo use the Tennis library, follow these steps:Install the library by runningpip install tennis.import librariesfromtennisimportmatchfromtennisimporttiebreakQuick StartHere's an example of how to simulate a tennis match using the Tennis library:fromtennisimportmatch# create a new match instancea=match.TennisMatch("a","b",{"num_games_to_win":6,"best_of_num_sets":3,"whos_serve":"a","with_AD":True})# call win_point() player "a" won the point by an "overhead, opponent unforced error, and a dropshot"a.win_point("a",["overhead"])a.win_point("a",['unforced_errors'])a.win_point("a",["win_by_dropshot"])# gets a string representation of the scoreboard. Player "a" score will be displayed on topprint(a.get_scoreboard("a"))# gets a string representation of the stats. Player "a" will be displayed on the leftprint(a.print_stats("a"))output:╔═════════════════════════════════════╗
              Match Score

    M  S  G  T
    0  0  40   *                a
    0  0  0                    b

╚═════════════════════════════════════╝


════════════════════════════════════════

a vs b
100 - First Serve Percentage - NA

3 - First Serve Points Won - 0

NA - Second Serve Percentage - NA

0 - Second Serve Points Won - 0

0 - Serve Games Won - 0

0 - Return Games Won - 0

3 - Total Points Won - 0

0 - Aces - 0

0 - Double Faults - 0

0 - Winners - 0

0 - Unforced Errors - 1

0 - Points Won By Volley - 0

1 - Points Won By Dropshot - 0

0 - Points Won By Overhead - 0



════════════════════════════════════════Here's an example of how to simulate a tennis tiebreak using the Tennis library:fromtennisimporttiebreak#create a new tiebreak instancetb=tiebreak.tiebreak("a","b",{"first_to_num_points":7,"win_by":2,"whos_serve":"a"})#player "a" wins the pointtb.win_point("a")#player "b" misses a first servetb.serve_fault("b")#returns a string representation of the scoreboardprint(tb.get_scoreboard("a"))output:╔═════════════════════════════════════╗
            Tiebreak Score

     T
     1                   a
     0  *                b

╚═════════════════════════════════════╝



════════════════════════════════════════

a vs b
100 - First Serve Percentage - NA

3 - First Serve Points Won - 0

NA - Second Serve Percentage - NA

0 - Second Serve Points Won - 0

0 - Serve Games Won - 0

0 - Return Games Won - 0

3 - Total Points Won - 0

0 - Aces - 0

0 - Double Faults - 0

0 - Winners - 0

0 - Unforced Errors - 1

0 - Points Won By Volley - 0

1 - Points Won By Dropshot - 0

0 - Points Won By Overhead - 0



════════════════════════════════════════Match MethodsTennisMatch (self, player1:str, player2:str, matchFormat:dict=None)Creates a new instance of a tennis match.Parametersplayer1 (str): The name of player 1.player2 (str): The name of player 2.matchFormat (dict): A dictionary of match settings.Examplematch=TennisMatch("a","b",{"num_games_to_win":2,"best_of_num_sets":3,"whos_serve":"a","with_AD":True})backup_match ()Creates a backup for the current tennis match instanceload_backup (self, backup_data)Loads a backup into a new matchParametersbackup_data (dict): The backup data created by the backup_match methodExamplebackup_data=match.backup_match()new_match=TennisMatch("dawda","nnnn",{"num_games_to_win":2,"best_of_num_sets":3,"whos_serve":"a","with_AD":True})new_match=new_match.load_backup(backup_data)print(new_match.match_stats("a"))win_point (self, player:str, how_won=[])method that handles a player winning or loosing a point. Do not call this method if it is a double fault. Instead, call theserve_fault(self, player:str)methodParametersplayer (str): The name of the player who won the point.how_won (Array): How the point was won (more than 1 in a method call is ok, just append them to the end of the list like ['winner','win_by_volley'])Ace: player A wins by by acing player b (Player A's serves the ball in and player B does not even touch the ball)winner: player A wins the point by hitting a winner. (The opponent doesnt touch the ball at all)unforced_error: player A wins the point because player B made an unforced error (An error that was not caused by player A. For example player B got an easy ball and missed it)win_by_volley: player A wins the point on a volley (Hitting the ball when it hasnt bounced right out of the air)win_by_dropshot: player A wins the point with a dropshot (player A lightly hits a short ball close to the net)win_by_overhead: player A wins the point via an overhead (player A "smashes" the ball right out of the air)Examplematch.win_point("a")match.win_point("b",['win_by_volley'])match.win_point("b",['win_by_volley','winner'])serve_fault (self, player:str)method to call when a server misses a first or second serveParametersplayer (str): The name of the player who missed the serveExample#double faultmatch.serve_fault("a")match.serve_fault("a")#missed first serve and made second servematch.serve_fault("a")match.win_point("a")win_game (self, player:str)A method that will win the game for a player. This method is intended for development and testing. The statistics for the match will be off.Parametersplayer (str): the player that will win the gameExamplematch.win_game("a")win_set (self, player:str)A method that will win the set for a player. This method is intended for development and testing. The statistics for the match will be off.Parametersplayer (str): the player that will win the setExamplematch.win_set("a")get_all_info (self)A method that will return all the info about the match in a dictionary formatreturn{"winner":self.winner,"game_history":self.gameHistory,"set_history":self.setHistory,"set_tiebreak_history":self.setTieBreakScoresHistory,"match_tiebreak_history":self.matchTieBreakScore,"match_format":self.matchFormat,"match_stats":self.matchStats}example output{'winner':'','game_history':[{'a':0,'b':0}],'set_history':[{'a':0,'b':0},{'a':0,'b':0}],'set_tiebreak_history':[],'match_tiebreak_history':{'a':1,'b':4},'match_format':{'num_games_to_win':2,'best_of_num_sets':3,'whos_serve':'b','with_AD':True},'match_stats':{'Aces':{'a':0,'b':0},'Double_fault':{'a':2,'b':1},'first_serve_percent':{'a':33,'b':33.33},'first_serve_points_won':{'a':0,'b':1},'second_serve_percent':{'a':0,'b':0},'second_serve_points_won':{'a':0,'b':0},'winners':{'a':0,'b':0},'unforced_errors':{'a':0,'b':0},'win_by_volley':{'a':0,'b':0},'win_by_dropshot':{'a':0,'b':0},'win_by_overhead':{'a':0,'b':0},'serve_games_won':{'a':0,'b':0},'return_games_won':{'a':0,'b':0}}}get_scoreboard (self, player:str)A method that will return a string representation of the current scoreboard.Parametersplayer (str): the player whos name and score will appear on the top half of the scoreboardExample Output╔═════════════════════════════════════╗MatchScoreMSGT1001a1004*b╚═════════════════════════════════════╝match_stats (self, player:str)A method that will return the statistics about the match in a string formatParametersplayer (str): the player who will appear on the left side of the statsExample Output════════════════════════════════════════avsb33-FirstServePercentage-33.330-FirstServePointsWon-10-SecondServePercentage-00-SecondServePointsWon-00-ServeGamesWon-00-ReturnGamesWon-01-TotalPointsWon-40-Aces-02-DoubleFaults-10-Winners-00-UnforcedErrors-00-PointsWonByVolley-00-PointsWonByDropshot-00-PointsWonByOverhead-0════════════════════════════════════════Tiebreak Methodstiebreak (self, player1:str, player2:str, matchFormat:dict=None)Creates a new instance of a tiebreak.Parametersplayer1 (str): the name of the first playerplayer2 (str): the name of the second playermatchFormat (dict): A dictionary of match settings.Examplematch=tiebreak("a","b",{"first_to_num_points":7,"win_by":2,"whos_serve":"a"})backup_tiebreak ()A method to backup tiebreak dataExamplematch=tiebreak("a","b",{"first_to_num_points":7,"win_by":2,"whos_serve":"a"})backup_data=match.backup_tiebreak()load_backup (self, backup_data)A method to load backup data from another tiebreak objectParametersbackup_data (dict): the data to load. use the backup_tiebreak method to obtain thisExample#backup old datamatch=tiebreak("a","b",{"first_to_num_points":7,"win_by":2,"whos_serve":"a"})backup_data=match.backup_tiebreak()#create new tiebreaknew_tiebreak=tiebreak("player1","player2")#load data into new tiebreaknew_tiebreak=new_tiebreak.load_backup(backup_data)#print out stats of old tiebreakprint(new_tiebreak.tiebreak_stats("a"))win_point (self, player:str, how_won=[])method that handles a player winning or loosing a point. Do not call this method if it is a double fault. Instead, call theserve_fault(self, player:str)methodParametersplayer (str): The name of the player who won the point.how_won (Array): How the point was won (more than 1 in a method call is ok, just append them to the end of the list like ['winner','win_by_volley'])Ace: player A wins by by acing player b (Player A's serves the ball in and player B does not even touch the ball)winner: player A wins the point by hitting a winner. (The opponent doesnt touch the ball at all)unforced_error: player A wins the point because player B made an unforced error (An error that was not caused by player A. For example player B got an easy ball and missed it)win_by_volley: player A wins the point on a volley (Hitting the ball when it hasnt bounced right out of the air)win_by_dropshot: player A wins the point with a dropshot (player A lightly hits a short ball close to the net)win_by_overhead: player A wins the point via an overhead (player A "smashes" the ball right out of the air)Examplematch.win_point("a")match.win_point("b",['win_by_volley'])match.win_point("b",['win_by_volley','winner'])tiebreak_stats (self, player:str)A method that returns a string representation of the statistics of the tiebreakParametersplayer (str): the name of the player whos stats will be displayed on the left sideExampleprint(tb.tiebreak_stats("a"))get_scoreboard (self, player:str)A method that returns a string representation of the current scoreParametersplayer (str): the name of the player whos stats will be displayed on the top of the scoreboardExampleprint(match.get_scoreboard("a"))output:╔═════════════════════════════════════╗MatchScoreMSGT1001a1004*b╚═════════════════════════════════════╝