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.
Initialization
Creates a new instance of MatchScoreHistory.
Keyword Arguments
- Name
teams- Type
- dict[TeamId, Team] | None
- Description
An optional dictionary mapping a
TeamIdto aTeamobject.
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 *