Player12
An open source football management simulator
Loading...
Searching...
No Matches
League Class Reference

Represents a football league containing teams and a leaderboard. More...

#include <league.h>

Public Member Functions

 League (LeagueID league_id, const std::string &league_name, const std::vector< TeamID > &initial_team_ids={}, std::optional< LeagueID > parent=std::nullopt, TieBreakRule tie_break_rule=TieBreakRule::GOAL_DIFFERENCE)
 Constructs a League object.
 
uint8_t getId () const
 Gets the league ID.
 
std::string getName () const
 Gets the name of the league.
 
const std::vector< TeamID > & getTeamIDs () const
 Gets the IDs of the teams in the league.
 
void addTeamID (TeamID team_id)
 Adds a team to the league.
 
void removeTeamID (TeamID team_id)
 Removes a team from the league.
 
uint16_t getPoints (TeamID team_id) const
 Gets the points of a specific team.
 
void addPoints (TeamID team_id, uint16_t points)
 Adds points to a specific team.
 
void setPoints (TeamID team_id, uint16_t points)
 Sets the points of a specific team.
 
void resetPoints ()
 Resets the points of all teams in the league to zero.
 
const std::map< TeamID, uint16_t > & getLeaderboard () const
 Gets the league leaderboard.
 
std::optional< LeagueID > getParentLeagueID () const
 Gets the parent league ID, if any.
 
TieBreakRule getTieBreakRule () const
 Ordering rule for teams level on points.
 

Private Attributes

const LeagueID id
 
std::string name
 
const std::optional< LeagueID > parent_league_id
 
TieBreakRule tie_break
 
std::vector< TeamID > team_ids
 
std::map< TeamID, uint16_t > leaderboard
 

Detailed Description

Represents a football league containing teams and a leaderboard.

Full tables (goal difference, form, tie-breakers) are computed from the played fixtures by Standings::compute; the leaderboard here only mirrors the points. Leagues form pyramids through the parent league ID.

Constructor & Destructor Documentation

◆ League()

League::League ( LeagueID  league_id,
const std::string &  league_name,
const std::vector< TeamID > &  initial_team_ids = {},
std::optional< LeagueID >  parent = std::nullopt,
TieBreakRule  tie_break_rule = TieBreakRule::GOAL_DIFFERENCE 
)

Constructs a League object.

Parameters
league_idThe unique ID for the league.
league_nameThe name of the league.
initial_team_idsOptional list of initial team IDs in the league.
parentOptional parent league ID.
tie_break_ruleHow teams level on points are ordered.

Member Function Documentation

◆ addPoints()

void League::addPoints ( TeamID  team_id,
uint16_t  points 
)

Adds points to a specific team.

Parameters
team_idThe ID of the team.
pointsThe points to add.

◆ addTeamID()

void League::addTeamID ( TeamID  team_id)

Adds a team to the league.

Parameters
team_idThe ID of the team to add.

◆ getId()

uint8_t League::getId ( ) const

Gets the league ID.

Returns
The ID of the league.

◆ getLeaderboard()

const std::map< TeamID, uint16_t > & League::getLeaderboard ( ) const

Gets the league leaderboard.

Points mirror of the fixture-derived table (see Standings::compute), refreshed by Game after every result.

Returns
A map of team IDs to their respective points.

◆ getName()

std::string League::getName ( ) const

Gets the name of the league.

Returns
The name of the league.

◆ getParentLeagueID()

std::optional< LeagueID > League::getParentLeagueID ( ) const

Gets the parent league ID, if any.

Returns
An optional containing the parent league ID.

◆ getPoints()

uint16_t League::getPoints ( TeamID  team_id) const

Gets the points of a specific team.

Parameters
team_idThe ID of the team.
Returns
The points of the team.

◆ getTeamIDs()

const std::vector< TeamID > & League::getTeamIDs ( ) const

Gets the IDs of the teams in the league.

Returns
A vector containing the team IDs.

◆ getTieBreakRule()

TieBreakRule League::getTieBreakRule ( ) const
inline

Ordering rule for teams level on points.

◆ removeTeamID()

void League::removeTeamID ( TeamID  team_id)

Removes a team from the league.

Parameters
team_idThe ID of the team to remove.

◆ resetPoints()

void League::resetPoints ( )

Resets the points of all teams in the league to zero.

◆ setPoints()

void League::setPoints ( TeamID  team_id,
uint16_t  points 
)

Sets the points of a specific team.

Parameters
team_idThe ID of the team.
pointsThe points to set.

Member Data Documentation

◆ id

const LeagueID League::id
private

◆ leaderboard

std::map<TeamID, uint16_t> League::leaderboard
private

◆ name

std::string League::name
private

◆ parent_league_id

const std::optional<LeagueID> League::parent_league_id
private

◆ team_ids

std::vector<TeamID> League::team_ids
private

◆ tie_break

TieBreakRule League::tie_break
private

The documentation for this class was generated from the following files: