Tennis Score
Level: IntermediateConcepts: State
Create a program to score a tennis match.
Requirements
- Implement tennis scoring rules:
              - 0 points = "Love"
- 1 point = "15"
- 2 points = "30"
- 3 points = "40"
- 4+ points = "Game" (if leading by 2)
 
- Handle deuce scenarios:
              - Both players at 40 = "Deuce"
- Player ahead by 1 = "Advantage"
- Player ahead by 2 = "Game"
 
- Support match scoring:
              - Games needed to win a set (typically 6, leading by 2)
- Sets needed to win the match (typically 2 or 3)
- Tiebreak rules (at 6-6)
 
Test Cases
| Scenario | Score | Expected Output | 
|---|---|---|
| Start of Game | 0-0 | "Love-Love" | 
| First Point | 1-0 | "15-Love" | 
| Two Points Each | 2-2 | "30-30" | 
| Deuce | 3-3 | "Deuce" | 
| Advantage | 4-3 | "Advantage Player 1" | 
| Game Win | 4-2 | "Game Player 1" | 
| Set Win | 6-4 | "Set Player 1" | 
| Match Win | 6-4, 6-3 | "Match Player 1" | 
Edge Cases to Consider
- Invalid score inputs
- Negative scores
- Impossible game states
- Tiebreak scenarios
- Match point situations
Tips
- Start with basic point scoring
- Add deuce handling next
- Then implement game scoring
- Finally add set and match scoring
- Consider using enums for score states