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 TeamId to a Team object.

Instantiation

class
MatchScoreHistory
from padelkit import MatchScoreHistory, TeamId

history = MatchScoreHistory()

methodhistory.add_point()

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.A or TeamId.B).

Returns

  • Name
    MatchScore
    Type
    MatchScore
    Description

    The new recalculated match state.

Usage

method
add_point
history.add_point(TeamId.A)

Output structure

TEAM A |   | 0 | 15
TEAM B |   | 0 |  0

methodhistory.modify_point()

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

method
modify_point
# 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  *

methodhistory.get_current_score()

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

method
get_current_score
score = history.get_current_score()
print(score)

Output structure

TEAM A |   | 0 |  0
TEAM B |   | 0 | 15  *

Was this page helpful?