MatchScoreHistory
MatchScoreHistory is the event-sourcing engine that drives the score calculation. It maintains a chronological record of points and recalculates the game state efficiently.
Properties
- Name
teams- Type
- dict[TeamId, Team] | None
- Description
The teams assigned to this match history, if any.
- Name
starting_server_team- Type
- TeamId
- Description
The team configured to start serving first in the match.
- Name
set_starting_servers- Type
- dict[int, dict[TeamId, Player]]
- Description
A dictionary mapping 1-based set indexes (e.g.,
1,2,3) to each team's chosen initial server for that set.
Initialization
Creates a new instance of MatchScoreHistory.
Keyword Arguments
- Name
teams- Type
- dict[TeamId, Team] | None
- Description
An optional dictionary mapping a
TeamIdto aTeamobject.
- Name
starting_server_team- Type
- TeamId
- Description
The team that starts serving first in the match.
- Name
set_starting_servers- Type
- dict[int, dict[TeamId, Player]] | None
- Description
A dictionary mapping a 1-based set index (e.g.,
1,2,3) to a nested dictionary mappingTeamIdto thePlayerchosen to start serving for that team in that set.
Instantiation
from padelkit import MatchScoreHistory, TeamId
history = MatchScoreHistory()
Adding Points
Adds a point won by a specific team to the history and returns the new recalculated score.
Required arguments
- Name
team- Type
- TeamId
- Description
The team that won the point (
TeamId.AorTeamId.B).
Returns
- Name
MatchScore- Type
- MatchScore
- Description
The new recalculated match state.
Usage
history.add_point(TeamId.A)
Output structure
TEAM A | | 0 | 15
TEAM B | | 0 | 0
Modifying Points
Corrects a mistake by overwriting a point at a specific index in the history, triggering an instant recalculation of the entire match state.
Required arguments
- Name
index- Type
- int
- Description
The 0-based index of the point in history to modify.
- Name
team- Type
- TeamId
- Description
The correct team that won the point.
Returns
- Name
MatchScore- Type
- MatchScore
- Description
The new recalculated match state.
Usage
# Overwrite the first point to be won by Team B
history.modify_point(0, TeamId.B)
Output structure
TEAM A | | 0 | 0
TEAM B | | 0 | 15 *
Retrieving Score
Iterates over the entire point history to compute the score up to the latest point.
Returns
- Name
MatchScore- Type
- MatchScore
- Description
The current recalculated match state.
Usage
score = history.get_current_score()
print(score)
Output structure
TEAM A | | 0 | 0
TEAM B | | 0 | 15 *
Setting Set Starting Servers
Configures the starting server player for a specific team in a specific set.
Note: The configured player must belong to the specified team. If the player is not a member of that team, a ValueError will be raised.
Required arguments
- Name
set_index- Type
- int
- Description
The 1-based index of the set (e.g.,
1for the first set,2for the second set).
- Name
team_id- Type
- TeamId
- Description
The team identifying (
TeamId.AorTeamId.B).
- Name
player- Type
- Player
- Description
The
Playerchosen to serve first for the team in that set.
Usage
from padelkit import Player, TeamId
player = Player("Juan Lebrón")
# Set server for Set 1
history.set_set_starting_server(set_index=1, team_id=TeamId.A, player=player)